Ejemplo n.º 1
0
        public static bool InvokeRunConsoleRedir(string Filename, string Args, out Int64 W32Res, out DataHRunConredirRunningData RunningData)
        {
            DataHRunConredir d = new DataHRunConredir();

            RunningData = new DataHRunConredirRunningData();

            d.File = Filename;
            d.Args = Args;
            W32Res = 0;

            RunningData.p2pSetTODOStacked = new Process2ProcessComm();
            RunningData.p2pSetTODOStacked.SetTODO("nothing", "");
            d.TODOPipeGUID = RunningData.p2pSetTODOStacked.GetGUID();
            RunningData.p2pGetResultStacked = new Process2ProcessComm();
            RunningData.p2pGetResultStacked.SetTODO("CONREDIR", d);
            if (RunningData.p2pGetResultStacked.StartPipe() == false)
            {
                FoxEventLog.WriteEventLog("Cannot start P2PC<1> for CONREDIR " + RunningData.p2pGetResultStacked.GetGUID(), EventLogEntryType.Error);
                return(false);
            }
            if (RunningData.p2pSetTODOStacked.StartPipe() == false)
            {
                RunningData.p2pGetResultStacked.ClosePipe();
                FoxEventLog.WriteEventLog("Cannot start P2PC<2> for CONREDIR " + RunningData.p2pSetTODOStacked.GetGUID(), EventLogEntryType.Error);
                return(false);
            }

            try
            {
                RunningData.proc = new Process();
                RunningData.proc.StartInfo.FileName        = Assembly.GetExecutingAssembly().Location;
                RunningData.proc.StartInfo.Arguments       = "-pipeaction " + RunningData.p2pGetResultStacked.GetGUID();
                RunningData.proc.StartInfo.UseShellExecute = true; //new console window!
                RunningData.proc.Start();
            }
            catch (Win32Exception ee)
            {
                W32Res = 0x00000000FFFFFFFF & ee.NativeErrorCode;
                Debug.WriteLine(ee.ToString());
                FoxEventLog.WriteEventLog("Cannot start P2PC for CONREDIR " + RunningData.p2pGetResultStacked.GetGUID(), EventLogEntryType.Error);
                return(false);
            }
            catch (Exception ee)
            {
                W32Res = 0x8000ffff;
                Debug.WriteLine(ee.ToString());
                FoxEventLog.WriteEventLog("Cannot start P2PC for CONREDIR " + RunningData.p2pGetResultStacked.GetGUID(), EventLogEntryType.Error);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public static void RunPipeClient()
        {
            Process2ProcessComm p2p = new Process2ProcessComm();

            if (p2p.ConnectPipe(ProgramAgent.PipeGUID) == false)
            {
                FoxEventLog.VerboseWriteEventLog("Cannot connect to pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error);
                return;
            }

            string Action = p2p.GetAction();

            if (Action == null)
            {
                FoxEventLog.VerboseWriteEventLog("Got no action data from pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error);
                return;
            }

            switch (Action.ToLower())
            {
            case "install":
            {
                PackageInstaller        inst = new PackageInstaller();
                DataHInstallPackageTODO todo = p2p.GetTODO <DataHInstallPackageTODO>();
                if (todo == null)
                {
                    FoxEventLog.VerboseWriteEventLog("Got no todo data from pipe " + ProgramAgent.PipeGUID, EventLogEntryType.Error);
                    return;
                }
                DataHInstallPackageResult result = new DataHInstallPackageResult();

                result.Return = inst.InstallPackage(todo.Filename, todo.CerCertificates, todo.Mode, todo.ZipIsMetaOnly,
                                                    out result.ErrorText, out result.res, out result.Reciept, todo.OtherDLL);

                if (inst.ScriptTempDLLFilename != null)
                {
                    FoxEventLog.VerboseWriteEventLog("Script DLL file = " + inst.ScriptTempDLLFilename, EventLogEntryType.Information);
                }

                result.TempDLLFilename = inst.ScriptTempDLLFilename;

                p2p.SetResult(result);
                break;
            }

            case "runuser":
            {
                DataHRunasUserTODO   todo = p2p.GetTODO <DataHRunasUserTODO>();
                DataHRunasUserResult res  = new DataHRunasUserResult();

                try
                {
                    Process p = new Process();
                    p.StartInfo.FileName        = todo.Filename;
                    p.StartInfo.Arguments       = todo.Args;
                    p.StartInfo.UserName        = todo.Username;
                    p.StartInfo.Password        = Utilities.MakeSecString(todo.Password);
                    p.StartInfo.UseShellExecute = false;
                    p.Start();
                }
                catch (Win32Exception ee)
                {
                    FoxEventLog.VerboseWriteEventLog("RUNUSER: Cannot run " + todo.Filename + " as user " + todo.Username + ": " + ee.ToString(), EventLogEntryType.Warning);
                    res.Result = 0x00000000FFFFFFFF & ee.NativeErrorCode;
                    Debug.WriteLine(ee.ToString());
                }
                catch (Exception ee)
                {
                    FoxEventLog.VerboseWriteEventLog("RUNUSER: Cannot run " + todo.Filename + " as user " + todo.Username + ": " + ee.ToString(), EventLogEntryType.Warning);
                    res.Result = 0x8000ffff;
                    Debug.WriteLine(ee.ToString());
                }

                p2p.SetResult(res);
                break;
            }

            case "conredir":
            {
                DataHRunConredir R = p2p.GetTODO <DataHRunConredir>();
                MainSTDIORedir.RunPipeConsoleEnd(p2p, R);
                break;
            }

            default:
                FoxEventLog.VerboseWriteEventLog("Action " + Action + " from pipe " + ProgramAgent.PipeGUID + "?? häh???", EventLogEntryType.Warning);
                return;
            }
        }