在运行模拟的 .NET 3.5 Web 应用程序中,我尝试通过以下方式执行进程:
var process = new Process
{ StartInfo =
{ CreateNoWindow = true,
FileName = "someFileName",
Domain = "someDomain",
Username = "someUserName",
Password = securePassword,
UseShellExecute = false
}
};
process.Start();
- 在 web.config 中将信任模式更改为完全没有解决。
-注意 var securePassword 是代码前面设置的 secureString。
这会抛出一个异常,消息为“访问被拒绝”。如果我删除用户名和密码信息,异常就会消失,但该进程以 aspnet_wp 启动,而不是我需要它的用户。
我在多个论坛中都看到过这个问题,但从未见过提供解决方案。
有任何想法吗?
您可以使用 ProcessStartInfo,它允许您指定凭据。诀窍在于密码是一个安全字符串,因此您必须将其作为字节数组传递。
代码可能类似于:
Dim startInfo As New ProcessStartInfo(programName)
With startInfo
.Domain = "test.local"
.WorkingDirectory = My.Application.Info.DirectoryPath
.UserName = "testuser"
Dim pwd As New Security.SecureString
For Each c As Char In "password"
pwd.AppendChar(c)
Next
.Password = pwd
'If you provide a value for the Password property, the UseShellExecute property must be false, or an InvalidOperationException will be thrown when the Process..::.Start(ProcessStartInfo) method is called.
.UseShellExecute = False
.WindowStyle = ProcessWindowStyle.Hidden
End With
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)