Пример #1
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;
            }
        }
Пример #2
0
        public static bool InvokeRunAsUser(string Filename, string Args, string Username, string Password, int SessionID, out DataHRunasUserResult ores, out Int64 W32Res)
        {
            ores   = null;
            W32Res = 0xe9;
            DataHRunasUserTODO d = new DataHRunasUserTODO();

            d.Filename = Filename;
            d.Args     = Args;
            d.Username = Username;
            d.Password = Password;

            Process2ProcessComm p2p = new Process2ProcessComm();

            p2p.SetTODO("RUNUSER", d);
            if (p2p.StartPipe() == false)
            {
                FoxEventLog.WriteEventLog("Cannot start P2PC for RUNUSER " + p2p.GetGUID(), EventLogEntryType.Error);
                return(false);
            }

            if (SessionID == 0)
            {
                try
                {
                    Process proc = new Process();
                    proc.StartInfo.FileName        = Assembly.GetExecutingAssembly().Location;
                    proc.StartInfo.Arguments       = "-pipeaction " + p2p.GetGUID();
                    proc.StartInfo.UseShellExecute = false;
                    proc.Start();
                    proc.WaitForExit();
                }
                catch (Win32Exception ee)
                {
                    W32Res = 0x00000000FFFFFFFF & ee.NativeErrorCode;
                    Debug.WriteLine(ee.ToString());
                    FoxEventLog.WriteEventLog("Cannot start P2PC for SYS RUNUSER " + p2p.GetGUID(), EventLogEntryType.Error);
                    return(false);
                }
                catch (Exception ee)
                {
                    W32Res = 0x8000ffff;
                    Debug.WriteLine(ee.ToString());
                    FoxEventLog.WriteEventLog("Cannot start P2PC for SYS RUNUSER " + p2p.GetGUID(), EventLogEntryType.Error);
                    return(false);
                }
            }
            else
            {
                if (ProgramAgent.CPP.StartAppAsUserWait(Assembly.GetExecutingAssembly().Location, "-pipeaction " + p2p.GetGUID(), SessionID) == false)
                {
                    W32Res = ProgramAgent.CPP.WGetLastError();
                    FoxEventLog.WriteEventLog("Cannot start P2PC Process for RUNUSER " + p2p.GetGUID() + " Error: 0x" + ProgramAgent.CPP.WGetLastError().ToString("X"), EventLogEntryType.Error);
                    p2p.ClosePipe();
                    return(false);
                }
            }

            ores = p2p.GetResult <DataHRunasUserResult>();
            p2p.ClosePipe();
            if (ores == null)
            {
                FoxEventLog.WriteEventLog("P2PC didn't return any data for RUNUSER " + p2p.GetGUID(), EventLogEntryType.Error);
                return(false);
            }

            return(true);
        }