C#:加载漫游配置文件并以用户身份执行程序

发布于 2024-07-09 03:46:36 字数 492 浏览 4 评论 0原文

在应用程序中,我需要使用其他用户的凭据执行其他程序。 目前我使用 System.Diagnostics.Process.Start< /strong> 执行程序:

public static Process Start(
   string fileName,
   string arguments,
   string userName,
   SecureString password,
   string domain
)

但是此功能不会从网络加载漫游配置文件 - 这是必需的。

我可以使用“runas /profile ...”加载配置文件并执行命令,但这会要求输入密码。 一定有更优雅的方式……

但是在哪里呢?

In an application I need to execute other programs with another user's credentials. Currently I use System.Diagnostics.Process.Start to execute the program:

public static Process Start(
   string fileName,
   string arguments,
   string userName,
   SecureString password,
   string domain
)

However this function does not load the roaming profile from the net - which is required.

I could use "runas /profile ..." to load the profile and execute the command, but that would ask for a password. There must be an more elegant way...

But where?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

℉服软 2024-07-16 03:46:36

我的解决方案(基于leppie的提示):

        Process p = new Process();

        p.StartInfo.FileName = textFilename.Text;
        p.StartInfo.Arguments = textArgument.Text;
        p.StartInfo.UserName = textUsername.Text;
        p.StartInfo.Domain = textDomain.Text;
        p.StartInfo.Password = securePassword.SecureText;

        p.StartInfo.LoadUserProfile = true;
        p.StartInfo.UseShellExecute = false;

        try {
            p.Start();
        } catch (Win32Exception ex) {
            MessageBox.Show("Error:\r\n" + ex.Message);
        }

My solution (based on leppie's hint):

        Process p = new Process();

        p.StartInfo.FileName = textFilename.Text;
        p.StartInfo.Arguments = textArgument.Text;
        p.StartInfo.UserName = textUsername.Text;
        p.StartInfo.Domain = textDomain.Text;
        p.StartInfo.Password = securePassword.SecureText;

        p.StartInfo.LoadUserProfile = true;
        p.StartInfo.UseShellExecute = false;

        try {
            p.Start();
        } catch (Win32Exception ex) {
            MessageBox.Show("Error:\r\n" + ex.Message);
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文