0

I am trying to insert msi file using asp.net application. when i run visual studio in administrators mode it is working fine but when i run it in normal mode it is not working. I had tried following code:

string installerFilePath;
installerFilePath = @"D:\ActivexPractice\test\test\NewFolder1\setup.msi";
System.Diagnostics.Process installerProcess = System.Diagnostics.Process.Start(installerFilePath, "/q");

can any body guide me on this how to install it without administrators right

klashar
  • 2,519
  • 2
  • 28
  • 38
  • if the installation requires admin rights, theres nothing you can do – Daniel A. White Feb 24 '17 at 13:44
  • While creating the msi file i have given the rights to everyone and it has fullControl – Dattaprasad Dhuri Feb 24 '17 at 13:46
  • 1
    the MSI itself doesn't have any rights. You can give people rights to _execute the MSI_, sure, but then the _actions that the MSI performs_ can themselves require different rights. If the install actions specified in the MSI require admin rights, then the user running the MSI (or in this case the user running your C# code, which is calling the MSI) must have the required rights to perform all the actions. – ADyson Feb 24 '17 at 13:48
  • 2
    I see this question is tagged asp.net - are you trying to get a web server to install a MSI file? Why would you want to do that? – stuartd Feb 24 '17 at 13:54

3 Answers3

6

You can use msiexec.exe to run installer. Here is sample code.

        Process installerProcess = new Process();
        ProcessStartInfo processInfo = new ProcessStartInfo();
        processInfo.Arguments = @"/i  D:\ActivexPractice\test\test\NewFolder1\setup.msi  /q";
        processInfo.FileName = "msiexec";
        installerProcess.StartInfo = processInfo;
        installerProcess.Start();
        installerProcess.WaitForExit();
Pankaj Kapare
  • 7,486
  • 5
  • 40
  • 56
  • [You can use DTF to install an MSI](https://github.com/glytzhkof/all/blob/master/DTFInstallMSI2/DTFInstallMSI2/Program.cs#L20) (a framework installed with the [WIX toolset](https://wixtoolset.org/)). It is a managed code wrapper for the Windows API so you can write regular C# code with nice classes to simplify the code. – Stein Åsmul Mar 01 '21 at 12:29
  • [Description of the files that make up DTF](https://serverfault.com/a/596519/20599) (*"Deployment Tools Foundation"*). Core file: `Microsoft.Deployment.WindowsInstaller.dll` (see source code link in above comment). – Stein Åsmul Mar 02 '21 at 06:44
  • [And finally a little snippet from stackoverflow with inline DTF sample](https://stackoverflow.com/a/1061606/129130). This one also has some installation instructions. – Stein Åsmul Mar 02 '21 at 06:59
0

If the MSI requires admin rights to install then it will ask for elevation in a UI install. Your /q is failing because a silent install is really silent and will not prompt for elevation. Note that limited users are not allowed to break security rules simply because they are doing an install.

So in that situation your launching process would need to be elevated, either by running as administrator or giving it a requiresAdministrator manifest so it asks for elevation.

When you fire off the install you need to make sure that your elevated state is used to fire off the install. The simplest way to guarantee this is to just call (p/invoke to...) MsiInstallProduct () directly from your code. The issue with Process.Start is that by default ProcessStartInfo.UseShellExecute is true and your elevated state (if you have one) will not be used to start the install. When the install is launched it needs to be a CreateProcess type of execution rather than a ShellExecute type so that your elevated credentials are used.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
0
static void installMSIs(string path)
{
    string[] allFiles = Directory.GetFiles(path, "*.msi");

    foreach (string file in allFiles)
    {
         System.Diagnostics.Process installerProcess = 
         System.Diagnostics.Process.Start(file, "/q");
         while (installerProcess.HasExited == false)
         {
             installerProcess.WaitForExit();
         }               
    }
}
dtwk2
  • 75
  • 6
  • 1
    Please don't post only code as an answer, but also provide an explanation of what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes – Ran Marciano Mar 01 '21 at 05:51