Archive: launch on start up


launch on start up
I amusing the modern UI. How do I add the application to launch at start up. I can not find any examples with the modern UI. Please help. Thanks in advance.


You mean Windows start up?
Just place a shortcut to your EXE in the Startup folder in the Windows Start menu > Programs > Startup like so.

Path to it would be:
"$SMPROGRAMS\Startup"

-Stu


let me make sure
What I want is (on Windows) when the user shuts down or restarts their machine, for the apoplication to start as well. Can you give me the code and place I put it in? I assume I have to put it in the unistaller as well. Here is my code. Thank you.

; -------------------------------
; Start


!define MUI_PRODUCT "Alarm Clock"
!define MUI_FILE "clock"
!define MUI_VERSION "1.0"
!define MUI_BRANDINGTEXT "Alarm Clock"
CRCCheck On


!include "${NSISDIR}\Contrib\Modern UI\System.nsh"

;!define TEMP $R0


;--------------------------------
;General

OutFile "Alarm.exe"
ShowInstDetails "nevershow"
ShowUninstDetails "nevershow"
SetCompressor "bzip2"

!define MUI_ICON "pepper.ico"
!define MUI_UNICON "noPepper3.ico"
!define MUI_SPECIALBITMAP "alarm.bmp"


;--------------------------------
;Folder selection page

InstallDir "$PROGRAMFILES\${MUI_PRODUCT}"


;--------------------------------
;Modern UI Configuration

;!define MUI_CUSTOMPAGECOMMANDS
!define MUI_WELCOMEPAGE
!define MUI_LICENSEPAGE
!define MUI_DIRECTORYPAGE
!define MUI_ABORTWARNING
!define MUI_UNINSTALLER
!define MUI_UNCONFIRMPAGE
!define MUI_FINISHPAGE

;--------------------------------
;Pages

;!insertmacro MUI_PAGECOMMAND_WELCOME
;Page custom IsFlashInstalled
;!insertmacro MUI_PAGECOMMAND_LICENSE
;!insertmacro MUI_PAGECOMMAND_DIRECTORY
;!insertmacro MUI_PAGECOMMAND_INSTFILES

;--------------------------------
;Language

!insertmacro MUI_LANGUAGE "English"

;--------------------------------
;Language Strings

;Header
;LangString TEXT_IO_TITLE ${LANG_ENGLISH} "InstallOptions Page"
;LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "Create your own dialog!"


;--------------------------------
;Data

LicenseData "Readme.txt"

;--------------------------------
;Reserve Files

;Things that need to be extracted on first (keep these lines before any File command!)
;Only useful for BZIP2 compression

;ReserveFile "checkFlash.ini"
;!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

;--------------------------------
;Installer Sections
Section "install" Installation info

;Add files
SetOutPath "$INSTDIR"

File "${MUI_FILE}.exe"
File "Readme.txt"

;create desktop shortcut
CreateShortCut "$DESKTOP\${MUI_PRODUCT}.lnk" "$INSTDIR\${MUI_FILE}.exe" ""

;create start-menu items
CreateDirectory "$SMPROGRAMS\${MUI_PRODUCT}"
CreateShortCut "$SMPROGRAMS\${MUI_PRODUCT}\Uninstall.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\${MUI_PRODUCT}\${MUI_PRODUCT}.lnk" "$INSTDIR\${MUI_FILE}.exe" "" "$INSTDIR\${MUI_FILE}.exe" 0

;write uninstall information to the registry
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "DisplayName" "${MUI_PRODUCT} (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}" "UninstallString" "$INSTDIR\Uninstall.exe"

WriteUninstaller "$INSTDIR\Uninstall.exe"

SectionEnd


;--------------------------------
;Uninstaller Section
Section "Uninstall"

;Delete Files
RMDir /r "$INSTDIR\*.*"

;Remove the installation directory
RMDir "$INSTDIR"

;Delete Start Menu Shortcuts
Delete "$DESKTOP\${MUI_PRODUCT}.lnk"
Delete "$SMPROGRAMS\${MUI_PRODUCT}\*.*"
RmDir "$SMPROGRAMS\${MUI_PRODUCT}"

;Delete Uninstaller And Unistall Registry Entries
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\${MUI_PRODUCT}"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_PRODUCT}"

SectionEnd


;--------------------------------
;MessageBox Section


;Function that calls a messagebox when installation finished correctly

Function .onInstSuccess
MessageBox MB_OK "You have successfully installed ${MUI_PRODUCT}. Use the desktop icon to start the program."
FunctionEnd


Function un.onUninstSuccess
MessageBox MB_OK "You have successfully uninstalled ${MUI_PRODUCT}."
FunctionEnd

Function .onInstSuccess
MessageBox MB_YESNO|MB_ICONQUESTION "Installation has completed. Launch ${MUI_PRODUCT} now?" IDNO NoLaunch
ExecShell open "$INSTDIR\${MUI_FILE}.exe"
NoLaunch:
FunctionEnd



;--------------------------------------
;Other function section

Function IsFlashInstalled
Push $R0
ClearErrors
ReadRegStr $R0 HKCR "CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}" ""
IfErrors lbl_na
StrCpy $R0 1
MessageBox MB_OK "Flash is installed. Whoopie!"
Goto lbl_end
lbl_na:
StrCpy $R0 0
MessageBox MB_OK "Flash is not Installed. Please visit macromedia.com and download the latest Flash plugin."
;Quit
lbl_end:
Exch $R0
FunctionEnd

;eof


Add this line after the desktop shortcut creation

CreateShortCut "$SMPROGRAMS\Startup\${MUI_PRODUCT}.lnk" "$INSTDIR\${MUI_FILE}.exe" "" 
And this line in the delete shortcuts area of the uninstaller
Delete "$SMPROGRAMS\Startup\${MUI_PRODUCT}.lnk" 


BTW In future could you attach long scripts rather than posting them.

Vytautas

Please attach big script, please :)
Second Startup folder is different in each Windows OS language.
First find the folder in the registry:


Function ".onInit"
ReadRegStr $0 HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Startup"
StrCmp $0 "" +1 +2
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "Startup"
Messagebox MB_OK $0
Quit
FunctionEnd

Don't forget:

SetShellVarContext current|all

Sets the context of $SMPROGRAMS and other shell folders. If set to 'current' (the default), the current user's shell folders are used. If set to 'all', the 'all users' shell folder is used. The all users folder may not be supported on all OSes. If the all users folder is not found, the current user folder will be used. Please take into consideration that a "normal user" has no rights to write in the all users area. Only admins have full access rights to the all users area. You can check this by using the UserInfo Plugin. See Contrib\UserInfo\UserInfo.nsi for an example.
Because permissions problems, you shouldn't allow non admins to install your software, btw, other installers like MS installer don't permit. :P

good luck
Ramon

$SMSTARTUP is easier than reading the registry.


Originally posted by kichik
$SMSTARTUP is easier than reading the registry.
You right :p. Forgot that :D