locked
Running exe from a msi RRS feed

  • Question

  • Hi all,

            I want to run an exe file when I double click on msi file. How can I do that? The exe is trying to move the msi to system directory and then run it as administrator. I am using visual c++ 6.0. Plz help...

    - Abhi

    Monday, April 12, 2010 7:37 AM

Answers

  • I didn't miss then, the only option to do what you want is to break the association with Windows Installer and that isn't a good thing. Especially since you are doing this for only one a few files. Whats more, most setup programs actually come as an exe/msi pair, so if the file you are installing does have an exe with it then you should be running that.

    Instead of trying to change the associations, why not just write the application so that it takes the path to the msi file as a parameter then drag and drop the msi file onto your exe file and have it use ShellExecute to start the installer. You can also make sure that the executable prompts to elevate normally by using a manifest or by using ShellExecute with the runas verb when starting off msiexec. This is a much more sensible design since it doesn't modify the system state.


    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    • Marked as answer by Abhi Deshmukh Monday, April 12, 2010 9:57 AM
    Monday, April 12, 2010 9:08 AM
  •            I used /i before filepath and now the code is working on windows7 also. The msi is getting properly installed.

    - Abhi

    • Marked as answer by Abhi Deshmukh Monday, April 12, 2010 9:56 AM
    • Unmarked as answer by Abhi Deshmukh Monday, April 12, 2010 9:57 AM
    • Marked as answer by Abhi Deshmukh Monday, April 12, 2010 9:57 AM
    Monday, April 12, 2010 9:56 AM

All replies

  • By default the shell associates msi files with msiexec.exe (the windows installer executable), so this means you want to break the association between msi and the Windows Installer executable. Modifying these settings will force all msi files to be run through this new executable and you then have to ask yourself would everyone who uses this software want that. Whats more, you are introducing a potential security risk into the systems which you modify to do this.

    If you want a particular msi file to be run using just your executable installer then you should look at modifying the executable so that it has a startup condition or maybe looks for a certain property and if not set then tells the person who run the msi file by itself to run it through the setup program. So this would be down to the msi author.

    If I misunderstood please provide detailed information on what you are trying to do. Although, since this is the VC Language, things like setup and deployment and Windows API don't really belong here since this is a forum for questions about Microsoft's implementation of the C++ language.


    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    • Proposed as answer by Sanjay More Thursday, December 2, 2010 8:56 AM
    Monday, April 12, 2010 8:26 AM
  •           I want to install a msi file from local user account. It does not get properly installed on windows7. I am using following steps to run it as administrator.

       1.
          Step 1

          Double-click the "My Computer" icon on the desktop. This opens an explorer window.
       2.
          Step 2

          Navigate to the location of the MSI file. If the MSI file is located on a CD or DVD, right-click the drive in the "My Computer" window and select "Explore."
       3.
          Step 3

          Right-click the MSI file and select "Copy." Go back to the "My Computer" main window and create a folder on the "C" drive named "MyMSI." Paste the MSI file in this directory.
       4.
          Step 4

          Click the Windows "Start" button and select "All Programs." Choose "Accessories" and then right-click on the "Command Prompt" icon. Choose "Run as Administrator." This opens the DOS command prompt with administrator rights.
       5.
          Step 5

          Type "C:\Windows\System32\msiExec.exe -i C:\myMSI\<filename>.msi." This uses the Microsoft Installer software installed on the machine to run the file copied in Step 3 as administrator.

            I am using batch file to run "C:\Windows\System32\msiExec.exe -i C:\myMSI\<filename>.msi." command. I am running this batch file from my exe using ShellExecute function since I want command prompt to be in run as administrator mode.

            Now I want this exe to execute first when I double click on msi and after that the remaining operation should continue. How can I do this?

    Monday, April 12, 2010 8:44 AM
  • I didn't miss then, the only option to do what you want is to break the association with Windows Installer and that isn't a good thing. Especially since you are doing this for only one a few files. Whats more, most setup programs actually come as an exe/msi pair, so if the file you are installing does have an exe with it then you should be running that.

    Instead of trying to change the associations, why not just write the application so that it takes the path to the msi file as a parameter then drag and drop the msi file onto your exe file and have it use ShellExecute to start the installer. You can also make sure that the executable prompts to elevate normally by using a manifest or by using ShellExecute with the runas verb when starting off msiexec. This is a much more sensible design since it doesn't modify the system state.


    Visit my (not very good) blog at http://c2kblog.blogspot.com/
    • Marked as answer by Abhi Deshmukh Monday, April 12, 2010 9:57 AM
    Monday, April 12, 2010 9:08 AM
  •              When I used ShellExecute with

                        lpVerb = "runas", lpFile = "msiexec.exe" and lpParameter = msifilepath

                 on windows7 only a window with title "windows installer" appears with ok button. But there is no further operation. The msi installation never get started. What may be the reason? This is my main problem. Thats why I am using the 5 step procedure that I mentioned in last reply. Plz help...

    - Abhi

    Monday, April 12, 2010 9:31 AM
  •            I used /i before filepath and now the code is working on windows7 also. The msi is getting properly installed.

    - Abhi

    • Marked as answer by Abhi Deshmukh Monday, April 12, 2010 9:56 AM
    • Unmarked as answer by Abhi Deshmukh Monday, April 12, 2010 9:57 AM
    • Marked as answer by Abhi Deshmukh Monday, April 12, 2010 9:57 AM
    Monday, April 12, 2010 9:56 AM