1

I have a program which I install using an NSIS script. The final step in the installer is to write to the registry Run key and have the program run on startup. I've confirmed that under

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run 

exists the key

MyCompany Program - C:\MyCompany\Program\launch.vbs

I've tried the key with and without quotes but there was no impact. I have confirmed the registry is reading from CurrentVersion\Run by adding

Notepad - C:\windows\notepad.exe

and Notepad now launches at startup. The launch.vbs script is a one liner to launch a script without the cmd.exe window:

'HideBat.vbs from https://superuser.com/questions/140047/how-to-run-a-batch-file-without-launching-a-command-window
CreateObject("Wscript.Shell").Run "cmd /c " & chr(34) & "C:\MyCompany\Program\run.cmd " & chr(34), 0, True

I've confirmed calling launch.vbs from an explorer window or from cmd.exe works as I expect (launching my program). msconfig confirms that C:\MyCompany\Program\launch.vbs is listed in the startup tab. The security tab of File Properties indicates all users should have read & execute privileges. Ditto the run.cmd actually getting called.

At this point I'm at a loss as to why my program isn't being launched, and I can't figure an efficient way to debug it.

System is Windows 7 Professional 64-bit.

  • To run a .vbs you need to call cscript I think. Put cscript your_script.vbs in the "Run" and see if that works. Falling that you'll have to write a .bat to call the same thing. – Kinnectus Mar 10 '15 at 20:34
  • Putting cscript in front of it, I see a very brief cmd.exe window which immediately terminates. Doesn't actually start the program. – guest Mar 10 '15 at 20:59
  • don't use cscript, but wscript instead. cscript makes the script work through a console window, causing you to always see one, and thats exactly what you want to avoid. putting a ' in front of a like makes you comment out a line. Do so on the line in your .vbs script. Add a new line and write: msgbox "test". now run the .vbs script and see if the msgbox pops up. Then reboot and see if it does too. This will tell you if the script loads or not, and where to look for the problem. – LPChip Mar 10 '15 at 21:12
  • Adding a msgbox "STARTING" before the call and a msgbox "ENDING" after the call, and I confirmed that the script is being called. Will have to figure out why running via startup isn't working, but calling the script afterwards is. Can cscript.exe be configured to print commands to stdout (like bash's -x)? – guest Mar 10 '15 at 21:25
  • I also notice your putting it in the 32-bit registry node, why? That could make a difference. – Ramhound Mar 10 '15 at 21:36
1

With the help of LPChip, I started messagebox debugging and confirmed the script was being launched, but erroring out. I updated the launch.vbs to

CreateObject("Wscript.Shell").Run "cmd /k " & chr(34) & "C:\MyCompany\Program\run.cmd " & chr(34), 1, True

(note the /k to keep the window alive, and 1 to show). From there, it was apparent that java isn't set on the classpath for scripts launched via CurrentVersion\Run. Hard-coding the path to java (which our clients will be forced to use anyways) in run.cmd solved the issue.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.