以管理员身份静默安装MSI



我正在尝试创建一个应用程序,该应用程序将从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);
}
}

与MSI上下文无关,您只是试图在特定的用户上下文下启动一个新进程(msiexec.exe(。检查下面的螺纹和其他类似的螺纹。

在Windows中:如何在另一个用户上下文下以管理员模式以程序方式启动进程?

最新更新