2008-12-03 81 views
1

在应用程序中,我需要使用其他用户的凭据执行其他程序。目前我使用System.Diagnostics.Process.Start执行程序:C#:加载漫游配置文件并以用户身份执行程序

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

然而这个功能不加载从网漫游配置文件 - 这是必需的。

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

但是在哪里?

回答

5

我的解决方案(基于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); 
     } 
+1

不错,我想更多的人应该张贴他们的最终解决方案:) – leppie 2008-12-03 18:41:25

相关问题