0

I am trying to create an application which will install the msi from the c# windows application, here i wanna take the input from user for UserName, Domain and password so that i can run the application in that user account. in the below code if i only give startInfo.Verb = "runas" its working but i want to provide the user name and password of admin and run it. can you guyz help me out.

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);
    }
}
Ravi Kanth
  • 1,182
  • 13
  • 38

1 Answers1

0

Disregarding the MSI context, you are simply trying to launch a new process (msiexec.exe) under a specific user context. Check the thread below and others alike.

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

Bogdan Mitrache
  • 10,536
  • 19
  • 34