System.Diagnostics.Process不接受凭据

System.Diagnostics.Process不接受凭据,process,permissions,credentials,processstartinfo,impersonation,Process,Permissions,Credentials,Processstartinfo,Impersonation,我正在尝试使用Process类执行批处理文件。此代码位于一个较大的代码段的中间,我使用LogoUnServer()和WiMeWistIntual.IimSimule()来模拟本地PC管理帐户。 我试图在进程内运行批处理文件,但没有在ProcessStartInfo中添加凭据,但这样做会导致批处理文件以静默方式失败-没有引发错误,并且批处理文件的预期输出从未返回(我正在异步读取stderr和stdout,fwiw) 然后,我将凭据添加到ProcessStartInfo,但现在,如果我不首先调用Wi

我正在尝试使用Process类执行批处理文件。此代码位于一个较大的代码段的中间,我使用LogoUnServer()和WiMeWistIntual.IimSimule()来模拟本地PC管理帐户。 我试图在进程内运行批处理文件,但没有在ProcessStartInfo中添加凭据,但这样做会导致批处理文件以静默方式失败-没有引发错误,并且批处理文件的预期输出从未返回(我正在异步读取stderr和stdout,fwiw)

然后,我将凭据添加到ProcessStartInfo,但现在,如果我不首先调用WindowsImpersonationContext.Undo(),则会出现“访问被拒绝”错误,如果我在Process.Start()之前调用.Undo(),则会出现“登录失败:未知用户名或错误密码”错误。对于多个帐户,我已三次检查用户名/密码/域是否正确

如果我的代码没有LogonUser()或WindowsIdentity.Impersonate()调用(ProcessStartInfo中没有凭据),则执行批处理文件并捕获批处理文件的输出不会有问题


我能够以本地管理员或任意本地用户帐户的身份从桌面成功运行批处理文件。我可以看到它的权限显示,它应该是可读/可执行的帐户,我试图运行它。这真的是一个很难缠的人;非常感谢您的帮助。

您在找这样的东西吗

Process proc = new Process();
proc.StartInfo.FileName = @"C:\WINNT\notepad.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;

proc.StartInfo.Domain = "mydomain.com"; // Domain of IIS Computer
proc.StartInfo.UserName = "kaung"; //Administrator for that computer
System.Security.SecureString password = new System.Security.SecureString();
password.AppendChar('m'); //Password
password.AppendChar('y');
password.AppendChar('p');
password.AppendChar('a');
password.AppendChar('s');
password.AppendChar('s');
password.AppendChar('w');
password.AppendChar('o');
proc.StartInfo.Password = password;

proc.Start();

问题是我需要重定向所有3个流;我只重定向了2(出,错,不入)。这基本上解决了问题