我如何作为另一个用户运行应用程序
本文关键字:用户 运行 应用程序 另一个 何作 | 更新日期: 2023-09-27 18:24:53
我知道这个问题已经被问过了,但我找不到任何答案。我有这样的代码,我正试图与特定用户一起运行一个应用程序,但给出了一个错误,即即使文件在那里,也找不到文件。
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();
}
}
}
感谢
错误为|系统找不到指定的文件|
如果使用
UseShellExecute = false
它忽略WorkingDirectory
您可以将UseShellExecute设置为true,并使用cmd shell。或者您将进程的位置添加到正在运行的进程的路径中:
string path = System.Environment.GetEnvironmentVariable("path");
path += ";" + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) + "''Cinegy''Cinegy Workflow 8.5.8''";
System.Environment.SetEnvironmentVariable("path", path);