Search code examples
windows-7registrynsis

Installer is ignoring WriteRegStr (trying to add application to Win Startup)


I'm installing an app to a Windows 7 machine (my app is targeting one specific device) and I'm trying to get it to run on OS startup/login.

It's a Silverlight OOB app, I thought this might have been a problem, but I tested it with Notepad and it still doesn't work.

I followed the example here:

!include "MUI.nsh"

Name "Tech Drive Installer"
OutFile "techdrive_setup.exe"
InstallDir "$PROGRAMFILES\Tech Drive"

RequestExecutionLevel admin
ShowInstDetails show

!insertmacro MUI_LANGUAGE "English"

Section
    SetOutPath "$INSTDIR"
    SetOverwrite ifnewer

    File "TechDrive.xap"
    ExecWait '"$PROGRAMFILES\Microsoft Silverlight\sllauncher.exe" /install:"$INSTDIR\TechDrive.xap" /origin:"http://localhost/TechDrive.xap" /shortcut:desktop'

    WriteRegStr HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Run\" "TechDrive" '"$PROGRAMFILES\Microsoft Silverlight\sllauncher.exe" 3388701632.localhost'
SectionEnd

Why wouldn't this be working?


Solution

  • The WriteRegStr call worked fine on this 32-bit Win7 machine. When writing to HKLM you should make sure you are admin.

    If you are using a 64-bit OS you will end up writing to the WOW64 part of the registry. In NSIS you can control this with the SetRegView instruction but either Run key should work.

    You could use Autoruns to verify that the value was added correctly or monitor it directly with Process Monitor. If it still fails to start I would double check the path to make sure it is correct. (Programs that run at startup are not allowed to require administrator rights either)