Process.Start 使用其他用户凭据导致 Win32exception:我们无法使用此凭据登录您,因为您的域不可用

问题描述

C# Process.Start 使用不同的用户名和域导致 Win32exception:我们无法使用此凭据登录您,因为您的域不可用。

但是,我能够使用 Win32 API CreateProcessWithlogonW

的相同凭据启动该进程

以下 C# 代码导致上述异常:

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);

但是,当我将以下 Win32 API CreateProcessWithlogonW 与 pinvoke 一起使用时,该进程成功启动:

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,"D:\\",ref si,out pi)

谁能帮我理解为什么 System.Diagnostic.Process 不会使用与 CreateProcessWithlogonW 一起使用的相同凭据启动进程

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)