How to launch an executable on the end of installa

2020-06-12 05:58发布

问题:

I'm launching my Windows application this way after the installation completes:

!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchApplication"

...

Function LaunchApplication
    ExecShell "" "$INSTDIR\Application.exe"
FunctionEnd

But this has a strange and undesired side-effect. Apparently is my application launched with admin rights.

I cannot drag & drop any data between a web browser (tested with Firefox and IE) and my application.

If I quit my application (the session started from NSIS), and restart it from the start menu icon everything works! - I can drag & drop to the browsers without problems.

So I suspect since in the beginning of installation there is a UAC request, somehow UAC rights are transferred to the process I'm launching after installation. Since the browsers run in a low security process Windows refuses to exhange any data with them (in the process instance that is launched with NSIS).

How to launch an exe from NSIS, so that this UAC/security problem does not happen?

回答1:

Use Exec '"$WINDIR\explorer.exe" "$TEMP\MyUnElevatedProcess.exe"'

Taken from http://mdb-blog.blogspot.com/2013/01/nsis-lunch-program-as-user-from-uac.html



回答2:

I recommend using the plugin ShellExecAsUser as mentioned by Anders. I use it for this exact same purpose like this:

!define MUI_FINISHPAGE_RUN_FUNCTION LaunchApplication

...

Function LaunchApplication
   SetOutPath $INSTDIR
   ShellExecAsUser::ShellExecAsUser "" "$INSTDIR\Application.exe" ""
FunctionEnd

Note the use of SetOutPath to ensure that Application.exe starts with installation folder as it's current directory. ShellExecAsUser does not set this.



回答3:

The UAC plugin can be used to get around this issue but it is a bit hard to use. You could also try ShellExecAsUser but I would recommend that you just don't use the run checkbox at all...



回答4:

Try This:

!define MUI_FINISHPAGE_RUN "$INSTDIR\Application.exe"
!insertmacro MUI_PAGE_FINISH

OR

Function .oninstsuccess   
Exec "$INSTDIR\Application.exe"   
FunctionEnd