问题
First hi to everyone !
I want to create a shortcut to a batch file that does not prompt the DOS window. For that I have seen that the following command works very well:
wscript.exe invisible.vbs my_batch_file.bat
My problem is that I would like to create the shortcut with this command via CMake and NSIS. My problem is that it seems I cannot give more than one parameter after "wscript.exe" in the following command in the CMakeLists.txt file:
list(APPEND CPACK_NSIS_CREATE_ICONS "
CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\link.lnk' 'wscript.exe' 'invisible.vbs my_batch_file.bat' icon.ico 0 SW_SHOWMINIMIZED
")
And the space between "invisible.vbs" and "my_batch_file.bat" is not parsed as I expected (i.e. as a space...). Could anyone help me with this ? Thanks a lot for every comment (method or code hint) !
回答1:
i don't now anything about NSIS, but maybe this is a hint in the right direction:
list(APPEND CPACK_NSIS_CREATE_ICONS "
CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\link.lnk' 'wscript.exe' 'invisible.vbs my_batch_file.bat' icon.ico 0 SW_SHOWMINIMIZED
")
also maybe, that 'invisible.vbs my_batch_file.bat' has to be ' invisible.vbs my_batch_file.bat' - starting with a space after '.
edit:
have you tried using "
instead of '
?
回答2:
I solved my problem using the "NSIS.template.in" file, in which I created the following macro
!macro CreateShortcutBat link bat_file
CreateShortCut '$SMPROGRAMS\\$STARTMENU_FOLDER\\${link}' 'wscript.exe' 'invisible.vbs ${bat_file}' icon.ico 0 SW_SHOWMINIMIZED
!macroend
Then in my CMakeLists.txt file, I only need to call the macro this way:
list(APPEND CPACK_NSIS_CREATE_ICONS "
!insertmacro CreateShortcutBat 'Shortcut.lnk' 'my_batch_file.bat'
")
回答3:
This short article shows exactly how to do what you want. It uses CPACK_NSIS_CREATE_ICONS_EXTRA and CPACK_NSIS_DELETE_ICONS_EXTRA to achieve the result. The example used there has two command line arguments, so you should be able to use the code there with simple modification. It also shows how to clean up after yourself and have the uninstaller remove the shortcut for you too.
来源:https://stackoverflow.com/questions/26804284/manage-shortcuts-arguments-for-nsis-createshortcut-method-via-cmake