【问题标题】:C# process start impersonation errorC#进程启动模拟错误
【发布时间】: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


【解决方案1】:

记事本不存储任何用户特定的设置。我确信所有 Office 产品都可以,如果 Acrobat 也可以,我也不会感到惊讶。

因此,首先要修复的是确保您的 ProcessStartInfoLoadUserProfile 设置为 true。这可能就足够了。

但是,有时应用程序在首次运行与任何后续启动时的行为也完全不同,因此我还要确保您至少有一次以预期目标用户身份启动了这些应用程序中的每一个,而您'实际上以该用户的身份身份登录到计算机(而不是以该用户身份启动单个进程)。

【讨论】:

  • 是的。设置 LoadUserProfile = true 解决了这个问题。谢谢。
【解决方案2】:

在您的代码示例中,您尝试在记事本中打开 pdf 文档。

只是检查一下,当您将文件名更改为 adobe exe(您可能需要添加 exe 的路径)而不是 notepad.exe 时会发生什么

【讨论】:

    猜你喜欢
    • 2010-09-25
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 1970-01-01
    • 2022-06-14
    • 1970-01-01
    相关资源
    最近更新 更多