Process.Start with other user credentials results in Win32exception: We can't sign you in with this credential because your domain isn't available

Viewed 153

C# Process.Start with different username and domain results in Win32exception: We can't sign you in with this credential because your domain isn't available.

However, I was able to launch the process with the same credentials with Win32 API CreateProcessWithLogonW

Following C# code results in above-mentioned exception:

ProcessStartInfo startinfo = new ProcessStartInfo();
startinfo.CreateNoWindow = false;
startinfo.UseShellExecute = false;
startinfo.FileName = "xyz";
startinfo.Arguments = "abc"
startinfo.RedirectStandardOutput = false;
startinfo.RedirectStandardError = false;
startinfo.UserName = "administrator";
startinfo.Domain = "abcde";
SecureString theSecureString = new NetworkCredential("", "Password").SecurePassword;
startinfo.Password = theSecureString;
Process extractImage = Process.Start(startinfo);

However, when I used the following Win32 API CreateProcessWithLogonW with pinvoke, the process got launched successfuly:

string appName="xyz";
string args = "abc";
string commandLine = appName + args;
PROCESS_INFORMATION pi;
STARTUPINFO si = new STARTUPINFO();
si.dwFlags |= (int)STARTF.STARTF_USESTDHANDLES;
si.wShowWindow = 0;
si.cb = Marshal.SizeOf(si);
CreateProcessWithLogonW("administrator", "abcde", "Password", LogonFlags.NetCredentialsOnly, null, commandLine, CreationFlags.DefaultErrorMode, 0, "D:\\", ref si, out pi)

Could anyone help me understand why System.Diagnostic.Process won't launch the process with the same credentials which works with CreateProcessWithLogonW?

0 Answers
Related