/// <summary> /// Create process with a token from a user logon. /// </summary> /// <param name="username">The username.</param> /// <param name="domain">The user's domain.</param> /// <param name="password">The user's password.</param> /// <param name="logon_flags">Logon flags.</param> /// <param name="config">The process configuration.</param> /// <returns>The created win32 process.</returns> public static Win32Process CreateProcessWithLogon(string username, string domain, string password, CreateProcessLogonFlags logon_flags, Win32ProcessConfig config) { using (var creds = new UserCredentials(username, domain, password)) { return(CreateProcessWithLogon(creds, logon_flags, config)); } }
internal static extern bool CreateProcessWithTokenW( SafeKernelObjectHandle hToken, CreateProcessLogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreateProcessFlags dwCreationFlags, [In] byte[] lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
internal static extern bool CreateProcessWithLogonW( string lpUsername, string lpDomain, string lpPassword, CreateProcessLogonFlags dwLogonFlags, string lpApplicationName, string lpCommandLine, CreateProcessFlags dwCreationFlags, [In] byte[] lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation);
/// <summary> /// Create process with a token from a user logon. /// </summary> /// <param name="credentials">The user's credentials.</param> /// <param name="logon_flags">Logon flags.</param> /// <param name="config">The process configuration.</param> /// <param name="throw_on_error">True to throw on error.</param> /// <returns>The created win32 process.</returns> public static NtResult <Win32Process> CreateProcessWithLogon(UserCredentials credentials, CreateProcessLogonFlags logon_flags, Win32ProcessConfig config, bool throw_on_error) { STARTUPINFO start_info = config.ToStartupInfo(); PROCESS_INFORMATION proc_info = new PROCESS_INFORMATION(); using (var password = credentials.GetPassword()) { return(Win32NativeMethods.CreateProcessWithLogonW(credentials.UserName, credentials.Domain, password, logon_flags, config.ApplicationName, config.CommandLine, config.CreationFlags, config.Environment, config.CurrentDirectory, ref start_info, out proc_info).CreateWin32Result(throw_on_error, () => new Win32Process(proc_info, config.TerminateOnDispose))); } }
public static Win32Process CreateProcessWithLogin(string username, string domain, string password, CreateProcessLogonFlags logon_flags, Win32ProcessConfig 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)); }
public static Win32Process CreateProcessWithLogin(string username, string domain, string password, CreateProcessLogonFlags logon_flags, string application_name, string command_line, CreateProcessFlags flags, string desktop) { Win32ProcessConfig config = new Win32ProcessConfig { ApplicationName = application_name, CommandLine = command_line, CreationFlags = flags, Desktop = desktop }; return(CreateProcessWithLogin(username, domain, password, logon_flags, config)); }
public static Win32Process CreateProcessWithLogin(string username, string domain, string password, CreateProcessLogonFlags logon_flags, string application_name, string command_line, CreateProcessFlags flags, string desktop) { STARTUPINFO start_info = new STARTUPINFO(); start_info.cb = Marshal.SizeOf(start_info); start_info.lpDesktop = desktop; PROCESS_INFORMATION proc_info = new PROCESS_INFORMATION(); if (!CreateProcessWithLogonW(username, domain, password, logon_flags, application_name, command_line, flags, IntPtr.Zero, null, ref start_info, out proc_info)) { throw new SafeWin32Exception(); } return(new Win32Process(proc_info)); }
public static Win32Process CreateProcessWithLogin(string username, string domain, string password, CreateProcessLogonFlags logon_flags, string application_name, string command_line, CreateProcessFlags flags, string desktop) { ProcessCreateConfiguration config = new ProcessCreateConfiguration(); config.ApplicationName = application_name; config.CommandLine = command_line; config.CreationFlags = flags; config.Desktop = desktop; return(CreateProcessWithLogin(username, domain, password, logon_flags, config)); }
/// <summary> /// Create process with a token from a user logon. /// </summary> /// <param name="credentials">The user's credentials.</param> /// <param name="logon_flags">Logon flags.</param> /// <param name="config">The process configuration.</param> /// <returns>The created win32 process.</returns> public static Win32Process CreateProcessWithLogon(UserCredentials credentials, CreateProcessLogonFlags logon_flags, Win32ProcessConfig config) { return(CreateProcessWithLogon(credentials, logon_flags, config, true).Result); }