【发布时间】:2017-10-31 14:06:57
【问题描述】:
我有一个 C# 格式的 Win Forms 应用程序,它在员工 PC 上运行。 在应用程序中,我使用 Process.Start 调用另一个可执行文件,但我传递了在域上具有管理员权限的用户的用户名和密码,因为员工没有运行可执行文件的权限。
可执行文件位于 C 上的文件夹中:
exe 在 Windows XP 机器上成功启动,但在 Windows 7 上失败并出现“拒绝访问”错误。 我没有找到解决方案。有什么想法吗?
try
{
var pass = new SecureString();
pass.AppendChar('b');
pass.AppendChar('l');
pass.AppendChar('a');
pass.AppendChar('b');
pass.AppendChar('l');
pass.AppendChar('a');
var pro = new ProcessStartInfo
{
FileName = AppDomain.CurrentDomain.BaseDirectory + "myExe.exe",
UserName = "username",
Password = pass,
Domain = "domain",
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
RedirectStandardInput = true
};
Process.Start(pro);
}
catch (Exception x)
{
MessageBox.Show("Failed to call updater.\n" + Help.ErrorMsg(x)); Application.Exit();
}
【问题讨论】:
-
"我传递了一个在域上具有管理员权限的用户的用户名和密码" - erm, wtf?!?如果您真的这样做,那么您就有安全问题并且您设计错误。您可能有 XY 问题...
-
你有问题的代码示例吗?
-
@MitchWheat 那么你有什么建议来运行这样一个可执行文件
-
您刚刚为您的所有用户(或任何入侵任何计算机的攻击者)提供了域管理员密码。这是一个糟糕的想法。
-
简单,在用户级别安装应用程序,而不是机器范围,因此不需要提升。使用 Wix,您可以将安装程序配置为按用户运行。 blogs.msdn.microsoft.com/astebner/2007/11/18/… 不知道您的安装程序。一个例子是 Chrome,它被安装到 C:\Users\lol\AppData\Local\Google\Chrome 而不是 \program 文件。如果必须是管理员,则使用 Active Directory 推出更新。 serverfault.com/questions/13111/…
标签: c# process credentials