Ejemplo n.º 1
0
        public static Win32Process CreateProcessAsUser(NtToken token, ProcessCreateConfiguration config)
        {
            STARTUPINFO start_info = config.ToStartupInfo();
            //start_info.wShowWindow = ;
            PROCESS_INFORMATION proc_info = new PROCESS_INFORMATION();

            using (var resources = new DisposableList <IDisposable>())
            {
                SECURITY_ATTRIBUTES proc_attr   = config.ProcessSecurityAttributes(resources);
                SECURITY_ATTRIBUTES thread_attr = config.ThreadSecurityAttributes(resources);

                if (!CreateProcessAsUser(token.Handle, config.ApplicationName, config.CommandLine,
                                         proc_attr, thread_attr, config.InheritHandles, config.CreationFlags, config.Environment,
                                         config.CurrentDirectory, ref start_info, out proc_info))
                {
                    if (!CreateProcessWithTokenW(token.Handle, 0, config.ApplicationName, config.CommandLine,
                                                 config.CreationFlags, config.Environment, config.CurrentDirectory, ref start_info, out proc_info))
                    {
                        throw new SafeWin32Exception();
                    }
                }

                return(new Win32Process(proc_info, config.TerminateOnDispose));
            }
        }
Ejemplo n.º 2
0
        public static Win32Process CreateProcessWithLogin(string username, string domain, string password,
                                                          CreateProcessLogonFlags logon_flags, ProcessCreateConfiguration config)
        {
            STARTUPINFO         start_info = config.ToStartupInfo();
            PROCESS_INFORMATION proc_info  = new PROCESS_INFORMATION();

            if (!CreateProcessWithLogonW(username, domain, password, logon_flags,
                                         config.ApplicationName, config.CommandLine, config.CreationFlags,
                                         config.Environment, config.CurrentDirectory, ref start_info, out proc_info))
            {
                throw new SafeWin32Exception();
            }

            return(new Win32Process(proc_info, config.TerminateOnDispose));
        }