【问题标题】:Installing a MSI as administrator silently以管理员身份静默安装 MSI
【发布时间】:2020-07-14 01:36:00
【问题描述】:

我正在尝试创建一个应用程序,它将从 c# windows 应用程序安装 msi,在这里我想从用户那里获取用户名、域和密码的输入,以便我可以在该用户帐户中运行应用程序。在下面的代码中,如果我只给 startInfo.Verb = "runas" 它的工作,但我想提供管理员的用户名和密码并运行它。你能帮帮我吗?

private void InstallProbe()
{
    try
    {
      bool gdfg=  IsRunAsAdmin();
        //processObj.InitializeProcess(txtUserName.Text, txtPassword.Text);
        string installcmd = "/c msiexec /i \"{0}\" /quiet TARGETDIR=\"{1}\" HOST=\"{2}\" PORT=\"{3}\" USEHTTPS=\"{4}\"  STEALTHMODE=\"{5}\"  ORGCODE=\"{6}\"";
        installcmd = string.Format(installcmd, txtFilePath.Text, @"%PROGRAMFILES%\ProHance Mate", "services.jamochatech.com", "8080", false, 0, "PHSALE");
        string uname, domain = string.Empty;
        //RunCommand("cmd", installcmd, processObj);
        if (txtUserName.Text.IndexOf("\\") > 0)
        {
            string[] strarr = txtUserName.Text.Split('\\');
            uname = strarr[1];
            domain = strarr[0];
        }
        else
        {
            uname = txtUserName.Text;
            domain = ".";
        }

        Process process = new Process();
        ProcessStartInfo startInfo = new ProcessStartInfo();
        //startInfo.Verb = "runas";

        startInfo.Domain = domain;
        startInfo.UserName = uname;
        startInfo.Password = ToSecureString(txtPassword.Text);
        startInfo.FileName = "cmd";
        startInfo.Arguments = installcmd;
        startInfo.CreateNoWindow = true;
        startInfo.UseShellExecute = false;
        startInfo.LoadUserProfile = true;
        MessageBox.Show(installcmd);
        process.StartInfo = startInfo;
        process.Start();
        process.WaitForExit(60000);
    }
    catch (Exception ex)
    {
        MessageBox.Show("Exception occured while installing the ProHance Mate " + ex.Message);
    }
}

【问题讨论】:

    标签: c# .net winforms windows-installer


    【解决方案1】:

    忽略 MSI 上下文,您只是尝试在特定用户上下文下启动一个新进程 (msiexec.exe)。检查下面的线程和其他类似的线程。

    In Windows: How do you programatically launch a process in administrator mode under another user context?

    【讨论】:

      猜你喜欢
      • 2022-01-23
      • 2012-07-11
      • 2015-01-22
      • 1970-01-01
      • 2016-06-07
      • 2017-05-27
      • 2023-04-06
      • 1970-01-01
      • 2014-11-02
      相关资源
      最近更新 更多