【问题标题】:How do i execute an external exe using a specific user如何使用特定用户执行外部 exe
【发布时间】:2021-05-12 00:41:39
【问题描述】:

我正在制作一个需要使用 FileSystemWatcher 监视文件系统的应用程序,以检测安装对文件系统的影响。

为了消除噪音,我想过滤由其创建用户创建的事件,并且该代码与 //BUILTIN //Administrator 用户一起使用,在安装时默认使用该用户。但仍然有相当多的噪音。然后我想到了创建一个特定的用户,我可以用它来运行安装文件,并过滤那个特定的用户,从而消除几乎所有的噪音。

这是我的流程创建和启动代码

private void executeInnoInstaller(string path, string fileName)
        {
            // Use ProcessStartInfo class
            ProcessStartInfo installerProces = new ProcessStartInfo();
            installerProces.CreateNoWindow = true;
            installerProces.UseShellExecute = false;
            installerProces.FileName = path + "\"" + fileName + "\"";
            installerProces.WindowStyle = ProcessWindowStyle.Normal;

            installerProces.UserName = "test";
            System.Security.SecureString encPassword = new System.Security.SecureString();
            
            foreach (System.Char c in "test")
            {
                encPassword.AppendChar(c);
            }
            encPassword.MakeReadOnly();
            installerProces.Password = encPassword;

            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(installerProces))
                {
                    exeProcess.WaitForExit();
                    //int exitCode = exeProcess.ExitCode;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }

此代码退出并拒绝访问。

操作系统=Windows

我已经尝试使用 SHIFT 从操作系统文件处理程序运行 installer.exe - 使用指定的用户右键单击,它可以工作。 VisualStudio 以管理员身份运行。 我尝试以管理员身份运行构建项目的exe文件,但它不起作用。

没有用户凭据,代码可以工作并使用 //BUILTIN //Administrator 帐户

有人知道吗?

提前感谢您的时间和精力。

【问题讨论】:

  • installerProces.FileName确切值是多少?
  • installerProces.FileName 的确切值可能是“C:\Sjabby\Installations håndtering\Innounp\HY-POLY free Installer.exe”
  • 我刚刚添加了这两行`installerProces.WorkingDirectory = path;` 没有任何区别。我没有连接到域。
  • 现在我有了 .UserName = Environment.UserDomainName + "\test";但现在它返回“用户名或密码错误”。我知道它不是。用户名是test,密码是test

标签: c# windows process user-accounts


【解决方案1】:

如果我将 UAC 安全级别调到最低,则此代码有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多