Archive: How to map icons to shortcuts and tell shortcuts to start up minimized?


How to map icons to shortcuts and tell shortcuts to start up minimized?
I suare, from my previous actions on this forum I tried searching for the following. How to create a shortcut linked to a special icon and how to start up that shortcut in minimized mode.

Currently, I have a lot of batch file shortcuts in the start menu and their icon is the default batch file icon. I would like to replace the default icon with a special one. Is this currently possible? Can someone please point me in the right direction?

Also, what is the command to tell a shortcut to start up minimized? The batch file shortcuts I would like to start up minimized as their action does do something else on the screen.

Thank you for any information on this :)


Please read the CreateShortcut documentation. All info is there.


Thank you Joost,

Unfortunately, the information required could not be found at the link you provided. Thank you very much for the information.

I am simply trying to link an icon to a shortcut and tell the shortcut to start up minimized. I feel though maybe this information is not critical for a build, it is indeed nice to know.

I am certain this could all be done on one line such as

CreateShortCut "$SMPROGRAMS\start.lnk" "$INSTDIR\start.bat" "$ICON=$INSTDIR\icon.ico" /MIN

Would or could it look something like that?

Thank you for your time


So what kind you find here: http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.3.4 ?

It explains everything (SW_SHOWMINIMIZED, icon.file etc.)


Thank you for that link. I just did a Ctrl+F on the page and got stuck here thinking this was it http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.1.5.

I am sorry if I seem lame for all of this. Thank you Joost


I cannot get the following to show up minimized.

  CreateShortCut "$DESKTOP\start.lnk" "$INSTDIR\start.bat" [SW_SHOWMINIMIZED]


It always starts up on screen... I believe I got the parameter right but something is no doubt wrong...

Please help

CreateShortCut "$DESKTOP\start.lnk" "$INSTDIR\start.bat" "" "icon.ico" "" SW_SHOWMINIMIZED

Boy was that sneaky... Thank you Joost,

So quotes instead of brackets and all parameters must be divided by two quotes "".

I would've missed that one for sure. Thank you Joost.


All shortcuts work and have been applied an icon. Excellent information Joost. How can I get the program which the user chooses at the end of installation to start up minimized?

Thank you


You don't have to divede parameters with two quotes. They are just empty parameters (you only have one icon, so you don't need an icon index).

To run the application that can be selected on the finish page minimized, use MUI_FINISHPAGE_RUN_FUNCTION (see the Modern UI Readme) and add the ExecShell command to the function.


I cannot explain how I tried so many different patterns but I cannot for the life of me get this to run right. Here is just a fraction of what I've tried.

!define MUI_FINISHPAGE_RUN_FUNCTION "EndLaunch"
!define MUI_FINISHPAGE_RUN_FUNCTION 'EndLaunch'
!define MUI_FINISHPAGE_RUN_FUNCTION EndLaunch
!define MUI_FINISHPAGE_RUN_FUNCTION Function EndLaunch
!define MUI_FINISHPAGE_RUN_EndLaunch
!define MUI_FINISHPAGE_RUN_FUNCTION ForgetAboutIt


My function looks like this

Function EndLaunch
ExecWait "$SMPROGRAMS\Project\Start.lnk"
FunctionEnd

(I know its an ExecWait function but just for the moment).

Here is the most famous of all the warnings...
1 warning:
install function "EndLaunch" not referenced - zeroing code (304-305) out


Can someone please help me with this task.

1) Make sure you got the latest development snapshot of NSIS: http://nsis.sf.net

2) The syntax is:

!define MUI_FINISHPAGE_RUN ;Run option on Finish page
!define MUI_FINISHPAGE_RUN_FUNCTION EndLaunch ;Call a function

Function EndLaunch
ExecWait "app.exe"
FunctionEnd

Thank you Joost,

I have NSIS version 2.0b3 and it seems your code does not work with it. I do then need the latest CVS version correct?

Thank you Joost.


This feature has been added about a week ago, so you need the latest CVS version (note that you also have to use the new page macro's and no page defines anymore).


Thank you Joost,

This thread will sort of point out why I wish to avoid upgrading to the latest development build. http://forums.winamp.com/showthread....hreadid=139789

Is it possible to hack NSIS so to launch ".vbs" scripts instead of .exe or .bat files? I've got a really simple .vbs script which will launch what ever I tell it to completely hidden from screen but NSIS will not launch a .vbs script... Is this hackable?

If I could launch a .vbs with nsExec or ExecWait this will completely take care of the minimize drama as then I could completely hide it from ever showing up upon launch.

I am just trying to avoid upgrading to a development build and learning NSIS all over again while trying to launch files either minimized or hidden from screen.

Thank you Joost


What's wrong with nsExec?


nsExec works for me while in a section for 2.0b3 and only during an installation; before it completes. It is placed directly before "Function un.onUninstSuccess" and seems to be executed last during the installation.

Section "ExecuteBeforeInstallCompletes"
nsExec::Exec "$INSTDIR\Core_Start.bat"
SectionEnd
It is perfect but the Finish page check box will not launch a function or a section in the current build of 2.0b3.

This is most likely the issue in regards to building the script as the latest build 2.0b4 just doesn't like the script which builds perfect in 2.0b3.

The script which builds perfect in 2.0b3 gives me 7 warnings, 1 error and no executable in the latest build. This is why I asked if it was possible to execute a .vbs file the same way I am able to launch a .bat file on the finish page.

I'd really like to somehow use nsExec as it seems like a magical solution but if it is not possible in the current build can I then hack NSIS to launch .vbs files on the finish page checkbox?

I just want to execute a .bat file from the finish page and have it launch in minimize mode or hidden if possible.

Thank you Joost

I have upgraded my script to work with 2.0b4 and I got it so far to compile with no errors or warnings. I tried the following suggestion...

!define MUI_FINISHPAGE_RUN ;Run option on Finish page
!define MUI_FINISHPAGE_RUN_FUNCTION EndLaunch ;Call a function

Function EndLaunch
ExecWait "app.exe"
FunctionEnd
Though it works and executes the batch file it sort of freezes on average 15 to 20 seconds on screen. The system doesn't go into a full freeze where it doesn't respond but the NSIS window blanks out and stays on screen for about 15 to 20 seconds. If I click on exit I do indeed get a program is not responding dialog box asking to kill it.

Is there a way to tell NSIS to execute the batch file and immediately exit somehow OR show a status screen with a load bar like Windows XP? The kind of load bar I am referring to is the kind which shows a few blips from left to right to signify to the user something is happening and that a freeze did not take place.

I am currently executing only 1 batch file. It has just two lines of instructions in it. 1 line starts a program and the other deletes a few files including itself.

I thought at first maybe deleting itself was the problem so I totally killed the ERASE line but that didn't help at all. It seems it still goes into a 15 second freeze.

Any workaround to this?

Thank you very much :)

If you want NSIS to exit, use Exec instead of ExecWait.


I am sorry Joost, I meant the NSIS screen freezes for about 15 to 20 seconds using the "nsExec" command. I like the nsExec command because it simply hides the dos box. But, it seems nsExec has a problem launching a batch file on the run page...

!define MUI_FINISHPAGE_RUN ;Run option on Finish page
!define MUI_FINISHPAGE_RUN_FUNCTION EndLaunch ;Call a function

Function EndLaunch
nsExec::Exec "$INSTDIR\Core_Start.bat"
FunctionEnd
Using the above piece of code freezes NSIS on screen for about 15 to 20 seconds. The following is the bat files contents
START http://www.vbgunz.com
ERASE /Q "Core_Start.bat"
It is a really simple bat file and I don't understand why NSIS chokes on it and freezes up on screen for 15 to 20 seconds over it.

One solution I've come up with is a programming friend of my mine by the name of Onno Broekmans, created a tiny exe file which when renamed the exact name of a bat file located in the same directory it will execute the bat file and hide it from ever showing up. Currently I use the exe file to launch the bat file instead and NSIS exits immediately with no freeze.
Function EndLaunch
nsExec::Exec "$INSTDIR\Core_Start.exe"
FunctionEnd
The size of the exe file is 40kb and adds only a 30KB overhead to the script. The coolest thing is you can add 40 more of the exe files and the overhead amazingly stays at just 30KB. NSIS is genious on that part. Anyway this small exe takes care of the 15 to 20 second NSIS freeze.

I will upload the tiny application when the Author approves its release.

Thank you Joost.

Why don't you handle the tasks of the batch file using NSIS code?


Hello Joost,

I only have two task at hand before I feel I complete this NSIS journey.

1. Launch a batch file without showing its dos box on the NSIS run page.
2. Launch a batch file at uninstall without showing the dos box.

1. Works with the following code but the NSIS run page freezes on screen for about 15 to 20 seconds when calling the bat file.

!define MUI_FINISHPAGE_RUN ;Run option on Finish page
!define MUI_FINISHPAGE_RUN_FUNCTION EndLaunch ;Call a function

Function EndLaunch
nsExec::Exec "$INSTDIR\Core_Start.bat"
FunctionEnd


It works but not as expected. It will run the bat file without showing the dos box but NSIS stays frozen on screen for 15 to 20 seconds. It is the freeze which presents the problem.

As for my second task, I can only use the "ExecWait" in the uninstall section. It performs its duty and does it well but it is unable to hide the dos box. The work around is I've inserted another exe to hide the dos box and use ExecWait to call the exe.

So without using the 3rd party application to complete the script I will be left with 2 problems.

1. the run page function to nsExec freezes NSIS for 15 to 20 seconds.
2. I am so far unable to call nsExec from the uninstall section.

Thank you Joost, If I get pass these two problems without involving 3rd party software I feel my installation task are complete using NSIS alone.

Thank you again Joost

1) Why not use NSIS code instead of the Core_Start.bat code?

2) Attach the script (uninstaller nsExec)


Hello Joost,

I was unaware of being able to run batch code direct from within NSIS. I currently thought this was a job for nsExec and its counterparts. I would appreciate a link to more information. Thank you Joost.

I will post my script for others to reference in the near future but at the moment here is a snippet of how I try to best apply "nsExec" to the uninstall section.

Function un.onInit
MessageBox...
Abort
nsExec::Exec "$INSTDIR\Core_Shut_Down.bat"
FunctionEnd
and/or
Section Uninstall
nsExec::Exec "$INSTDIR\Core_Shut_Down.bat"
...
DeleteRegKey HKLM...
SetAutoClose true
SectionEnd
So far I am thinking I must turn the nsExec into a function and call the function from the uninstall but I do not know how to do that at the moment.

Thank you Joost

nsExec does work from the uninstaller. Are you sure you did not make another error?

I mean: Use NSIS commands instead of batch file commands, i.e. put Delete in the function instead of the batch command DEL, etc.