1

Background: The installation of our application requires Admin privileges. After the installer has finished we are calling the newly installed program from the installer, and it opens in an Admin window. (This is at least how it works on Windows) Then when we click on the icon to run the program, it opens another window (thus two instances of the app are running -- not a good thing.)

Is it possible run both the installer and the app from a batch file, so that only after the installer is closed, the app opens in an non-admin window? (In our app the installer asks for the admin privileges, so the batch file should not do that.)

I tried experimenting with this using "Everything.exe" (an excellent app that requires admin privileges).

REM Test batchfile for opening two apps
"C:\Program Files (x86)\Everything\Everything.exe"
Notepad.exe

unfortunately as soon as Admin privileges are granted to "Everything.exe", Everything loads in the Admin window, and the Notepad loads in the non-admin window.

Is there a way to open the app in non-admin windows after the installer exits?"

JimmyB
  • 12,101
  • 2
  • 28
  • 44
Veet Vivarto
  • 371
  • 3
  • 11
  • possible duplicate of [How to wait for a process to terminate to execute another process in batch](http://stackoverflow.com/questions/8177695/how-to-wait-for-a-process-to-terminate-to-execute-another-process-in-batch) – JimmyB Apr 16 '14 at 08:02
  • Use `start /wait` in batch, but is batch really the right solution? – David Heffernan Apr 16 '14 at 08:05
  • 1
    There is no reliable way. For admins you can strip the extra privileges from the token but for non admins who run under an admins token it won't work. But none of this is available to a batch file. This explains it and triesto give you a procedurein C to help. http://blogs.msdn.com/b/oldnewthing/archive/2013/11/18/10468726.aspx – tony bd Apr 16 '14 at 08:40
  • Perhaps runas command may help your problem. Runas /? – tony bd Apr 16 '14 at 08:41
  • Hanno Binder, I just tried your suggestion to use the "how to wait for a process to terminate to execute another process in batch –" Unfortunately it did not work. I believe the reason is that the first process runs in an Admin window, and the second does not. The second one open in a non-admin window without waiting for the first to exist. – Veet Vivarto Apr 16 '14 at 12:04

1 Answers1

2

You should be able to use MSI (Windows Installer) to install the product with "elevated rights" as opposed to "administrator rights". Windows Installer features a built-in mechanism to impersonate an administrator for the installation transaction when the setup is launched in a regular users login session (there are some policy settings that have to be enabled).

It should also be possible to run an MSI with administrator rights and launch an application from the final setup dialog with regular user rights (perhaps not if launched from an admin rights cmd.exe - not sure, it should launch the msi by right click run as admin) This is possible because the MSI GUI never runs with elevated privileges - it is the installation transaction launched by the GUI that has elevated rights. Once the transaction is complete, the control returns to the GUI running with regular rights. From here you can launch the app via a button click.

This description is somewhat simplified, I'll leave it at that since MSI might not be an option for you.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164