0
我知道这是问题已被问到,但我找不到任何答案。我有这个代码,我试图运行一个特定用户的应用程序,但给出错误,即使文件存在,该文件也找不到。我如何以另一个用户的身份运行应用程序
static void Main(string[] args)
{
System.Diagnostics.ProcessStartInfo myProcess = new System.Diagnostics.ProcessStartInfo("cinegy.exe");
myProcess.WorkingDirectory =Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)+ "\\Cinegy\\Cinegy Workflow 8.5.8\\";
System.Security.SecureString password = new System.Security.SecureString();
string uspw = "mypass";
foreach (char c in uspw)
{
password.AppendChar(c);
}
myProcess.UserName = "myuser";
myProcess.Password = password;
myProcess.Domain = "mydomain";
myProcess.UseShellExecute = false;
try
{
System.Diagnostics.Process.Start(myProcess);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
感谢
错误是|系统找不到指定的文件|
能否请您发表你得到确切的错误? – m0skit0 2012-02-17 11:09:59
并且您的新用户在该文件夹中具有读取/执行权限? – rene 2012-02-17 11:10:49
检查此文章:http://stackoverflow.com/questions/559719/windows-impersonation-from-c-sharp – rkosegi 2012-02-17 11:11:34