我尝试在网络服务帐户下启动子进程,但我无法获得正确的用户名/密码组合。代码:
var proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "Test2.exe";
proc.StartInfo.Arguments = args[0];
proc.StartInfo.Domain = "NT AUTHORITY";
proc.StartInfo.UserName = "NETWORK SERVICE";
proc.StartInfo.Password = new SecureString();
proc.Start();
答案 0 :(得分:1)
快速谷歌搜索显示this page。看来你需要依赖win32 api,特别是这些方法:
[DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool LogonUser(string username, string domain,
string password, LogonType logonType,
LogonProvider logonProvider,
out IntPtr userToken);
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool ImpersonateLoggedOnUser(IntPtr userToken);
我猜测在.Net中执行此操作并不是那么简单的原因是因为这是一个非常奇怪的要求,因为这个用户应该被Windows服务使用,而这不是执行代码的关注点。 / p>