【发布时间】:2017-10-21 07:56:37
【问题描述】:
我正在尝试使用不同的用户运行该进程。当我运行正常的“notepad.exe”时,它工作正常。但是当我将文件更改为具有完整路径的任何其他可执行文件时(C:\\Program Files\\Microsoft Office\\Office15\\Excel.exe)或(C:\\Program Files (x86)\\Adobe\\Acrobat Reader DC\\Reader\\AcroRd32.exe) 它不起作用。而是给出了图片中附加的错误。
有什么建议吗...??
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();
}
【问题讨论】:
-
任何帮助家伙....???
标签: c# process impersonation processstartinfo