C# C进程启动模拟错误
我正在尝试使用不同的用户运行该进程。当我运行normalnotepad.exe时,它工作正常。但是,当我将文件更改为具有完整路径C:\\Program Files\\Microsoft Office\\Office15\\Excel.exe或C:\\Program Files x86\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe的任何其他可执行文件时,它将不起作用。取而代之的是在图片中附加的错误 有什么建议吗C# C进程启动模拟错误,c#,process,impersonation,processstartinfo,C#,Process,Impersonation,Processstartinfo,我正在尝试使用不同的用户运行该进程。当我运行normalnotepad.exe时,它工作正常。但是,当我将文件更改为具有完整路径C:\\Program Files\\Microsoft Office\\Office15\\Excel.exe或C:\\Program Files x86\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe的任何其他可执行文件时,它将不起作用。取而代之的是在图片中附加的错误 有什么建议吗 在代码示例中,您试图在记事本中打开p
在代码示例中,您试图在记事本中打开pdf文档
只需检查一下,当您将文件名更改为adobe exe时会发生什么,您可能需要将路径添加到exe而不是记事本。exe不存储任何用户特定的设置。我确信所有的办公产品都是这样,如果Acrobat也这样做,我也不会感到惊讶 所以,要解决的第一件事是确保设置为true。这可能就足够了
但是,有时应用程序在第一次运行时的行为与任何后续启动时的行为都大不相同,因此我还要确保您至少有一次作为预期目标用户启动了这些应用程序,而您实际上是以该用户的身份登录到计算机上,而不是以该用户的身份启动单个进程。有任何帮助吗…??是的。设置LoadUserProfile=true解决了该问题。谢谢
static void Main(string[] args)
{
SecureString securePwd = new SecureString();
string password = "P@ssw0rd";
SecureString sec_pass = new SecureString();
Array.ForEach(password.ToArray(), sec_pass.AppendChar);
sec_pass.MakeReadOnly();
Process p = new Process();
ProcessStartInfo ps = new ProcessStartInfo();
p.StartInfo.FileName = "notepad.exe";
p.StartInfo.Arguments = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\welcome.pdf";
p.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\";
p.StartInfo.ErrorDialog = true;
p.StartInfo.EnvironmentVariables.Add("TempPath", "C:\\Temp");
p.StartInfo.Domain = "testdom";
p.StartInfo.UserName = "testuser";
p.StartInfo.Password = sec_pass;
p.StartInfo.RedirectStandardError = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
StreamReader myStreamReader = p.StandardOutput;
// Read the standard error of net.exe and write it on to console.
Console.WriteLine(myStreamReader.ReadLine());
p.Close();
}