Skip to content
⌘ NSIS Forum Archive

Run program on startup,some help

12 posts

mrjohn#

Run program on startup,some help

Hi,I try to create installer for this backup registry software :

I want to automatically run it on windows startup,and I've done using
WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Run"
application seems to run on startup and creates registry backups but in msconfig instead of application name I see exe run options:



main installer code:
 RequestExecutionLevel admin
 
Section ""
  SetAutoClose true
  SetOverwrite on
  detailprint "RegBak"
    SetDetailsPrint none
      CreateDirectory "$SMPROGRAMS\REGBAK"
 SetOutPath $INSTDIR
  FILE "regbak.exe"
  FILE "regbak.chm"
  FILE "RegOpt.ini"
   SetOutPath "$INSTDIR"
   WriteUninstaller "$INSTDIR\Uninstall.exe"
   CreateShortCut "$SMPROGRAMS\REGBAK\Uninstall.lnk" "$INSTDIR\Uninstall.exe"
   CreateShortCut "$SMPROGRAMS\REGBAK\RegBak.lnk" "$INSTDIR\regbak.exe"
 WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Run" \
 "RegBak" '"$INSTDIR\regbak.exe" %USERPROFILE%\_RegBak\AUTOBACKUP\<DATE> /reg:suo /limitdays:20 /silent'
  SectionEnd 
thanks for any help!
mrjohn#
Hi,because with code above I could not run the program on windows 8.1 startup,I decided to create a schedule task
I used the script from there : http://nsis.sourceforge.net/Scheduled_Tasks
my code
SetOutPath $TEMP
  push "RegBak"
  push "Backup registry"
  push "$INSTDIR\regbak.exe"
  push "$INSTDIR"
  push "%USERPROFILE%\_RegBak\AUTOBACKUP\<DATE> /reg:suo /limitdays:20 /silent"
  push \
    "*(&l2, &i2 0, \
      &i2 2006, &i2 1, &i2 1, \
    &i2 0, &i2 0, &i2 0, \
    &i2 0, &i2 0, \
    i 0, i 0, \
    i 0, \
    i 1, \
    &i2 1, &i2 00, &i2 0, i 0, &i2 0) i.s"
  push "Administrator"
  push "password"
  Call CreateTask
  Pop $0 
creates the task,but it doesn't run if I right click and select RUN I got : could not start
,it only works if I put user and password,but my installer should work on every computer not on my
I found also in the link above

TASK_FLAG_RUN_ONLY_IF_LOGGED_ON (0x2000)
it doesn't work

google chrome installer creates schedule task for updates without knowing my password
any help?

thaks!
Anders#
The initial registry code looks OK to me, maybe you could change the string bit by bit by hand until msconfig is able to parse it, it could just be a msconfig bug...
mrjohn#
Thanks for the answer,no problem now,seems to work in XP
The method with startup work only on xp,for W8 I create a schedule task but not with script above,I used SchTasks
SchTasks doesn't work in XP so I used os detection and seems ok

${if} ${isWinXP}
  WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Run" \
  "RegBak" '"$INSTDIR\regbak.exe" %USERPROFILE%\_RegBak\AUTOBACKUP\<DATE> /reg:suo /limitdays:20 /silent'
${else}
  nsExec::Exec 'SchTasks /Create /TN RegBak /TR "$INSTDIR\regbak.exe \
   $PROFILE\_RegBak\AUTOBACKUP\<DATE> /reg:suo /limitdays:20 /silent" \
   /SC ONSTART /RU SYSTEM'
${endif} 
thanks!

Originally Posted by Anders View Post
The initial registry code looks OK to me, maybe you could change the string bit by bit by hand until msconfig is able to parse it, it could just be a msconfig bug...
Anders#
And if you quote the "%USERPROFILE%\_RegBak\AUTOBACKUP\<DATE>" part?

That run entry should work or at least start the .exe. Not sure if RegBak will expand %USERPROFILE% though...
mrjohn#
Added quote,on xp works,I'll test today schedule creation on W8
thanks

${if} ${isWinXP}
  WriteRegStr HKEY_LOCAL_MACHINE "Software\Microsoft\Windows\CurrentVersion\Run" \
  "RegBak" '"$INSTDIR\regbak.exe" "%USERPROFILE%\_RegBak\AUTOBACKUP\<DATE>" /reg:suo /limitdays:20 /silent'
${else}
  nsExec::Exec 'SchTasks /Create /TN RegBak /TR "$INSTDIR\regbak.exe \
   $\"$PROFILE\_RegBak\AUTOBACKUP\<DATE>$\" /reg:suo /limitdays:20 /silent" \
   /SC ONSTART /RU SYSTEM'
${endif} 
mrjohn#
bad news,I've tested on W7x64 and doesn't seems to work,quotes seems to be the problem
current script
 nsExec::Exec '"$SYSDIR\schtasks.exe" /Create /TN RegBak /TR "$INSTDIR\regbak.exe  \
   $PROFILE\_RegBak\AUTOBACKUP\<DATE> /reg:suo /limitdays:20 /silent" \
   /SC ONSTART /RU SYSTEM' 

also the same on XP

If I use browse button,quotes are added,with NSIS I couldn't do it,tried:
nsExec::Exec 'SchTasks /Create /TN RegBak /TR "$\"$INSTDIR\regbak.exe$\"  \
   $\"$PROFILE\_RegBak\AUTOBACKUP\<DATE>$\" /reg:suo /limitdays:20 /silent" \
   /SC ONSTART /RU SYSTEM' 
thanks
mrjohn#
Hi,with run key could't make it work with W7 and 8
for the moment,I found a little tip on this post
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.


I have used GetFullPathName /SHORT and task works on XP/W8,I think it also will work on 7.
There should be a problem using the tip above?
Thanks


Originally Posted by Anders View Post
The run key should work on all systems, stop trying to use a task!
Anders#
Originally Posted by mrjohn View Post
There should be a problem using the tip above?
Not all paths have a short name...
mrjohn#
The run key doesn't work for me in W8.1 pro,tested again,startup item is present but it doesn't run,using schedule works fine.

thanks
Originally Posted by Anders View Post
The run key should work on all systems, stop trying to use a task!