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

Bla*_*laM 1 .net c# impersonation runas roaming-profile

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

public static Process Start(
   string fileName,
   string arguments,
   string userName,
   SecureString password,
   string domain
)
Run Code Online (Sandbox Code Playgroud)

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

我可以使用"runas/profile ..."来加载配置文件并执行命令,但这会要求输入密码.必须有一个更优雅的方式......

但是哪里?

Bla*_*laM 6

我的解决方案(基于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);
        }
Run Code Online (Sandbox Code Playgroud)