Archive: Avoiding a bad way of starting an application on login / startup


Avoiding a bad way of starting an application on login / startup
I have a Tcl script that I want to provide a notification window when someone connects to a port it's listening to and provides specific information, and I'd like to have the script started when the user logs in, or possibly when the computer is started up.

I'd imagine that if I poked around other resources I could find a bad way to get it to work on my system... and wanted to ask people on this system, who probably know the right way, what's the "best engineering" approach in this case?

Jonathan


I'm unfamiliar with what a TCL script is, but if it is, or can be package in, an executable, then you can use the registry in windows to set it to run at startup. You can either do this for a particular user by adding a registry entry to HKCU, or do it for all users by adding it to HKLM

HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

The other option is to place a shortcut into the "startup" folder of the start menu. Once again, you can do this under an individual user's start menu or the All Users startmenu.

If you want to make it easy for the user to enable/disable this feature, you should do it through the start menu.

The registry is probably the easier method though, and what I would go with. If I wanted to allow the user to disable the "Run at startup", then I'd provide a GUI that allows them to do that, and the application would remove the registry entry for them.

IMO it is a really awful practice to set a program to run at startup and not provide an obvious/intuitive way to let the user disable that feature. Additionally I'd say that the installer should even have a "Run at startup" checkbox so the user can disable the feature.

Oh, the other option is to install a Windows Service. One big difference will be that the above methods will not run the program until a user logs in. A windows Service can startup before anyone has even logged in, which is great if you need the application to run on a server, where users are not normally logged in.


TCL is a scripting language, something of a lesser-known cousin to Perl and Python--it is indeed an executable, although interpreted rather than being a standalone .exe.

So the installer, to work for the current user, should be something like:

WriteRegStr HKCU "Software\MicroSoft\Windows\CurrentVersion\Run" "${_APP_NAME}" "${_APP_NAME}"

Or is part of that a bit off?

Thanks for your help,
Jonathan


I think that's right, except the value parameter should be the full path to the executable, something like this I think:

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${_APP_NAME}" "C:\blah\TLC.exe"

Edit: I'm not sure if registry keys are case sensitive, but I noticed you have MicroSoft instead of Microsoft. Thought I'd point that out if you have a problem.


Thanks you, in particular for the capitalization note.

Originally posted by AaronLS
I think that's right, except the value parameter should be the full path to the executable, something like this I think:

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${_APP_NAME}" "C:\blah\TLC.exe"

Edit: I'm not sure if registry keys are case sensitive, but I noticed you have MicroSoft instead of Microsoft. Thought I'd point that out if you have a problem.

WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${_APP_NAME}" "C:\blah\TLC.exe"
Followup question: How, in the uninstaller, do I delete the registry key or part of key created as quoted above?

Thanks,
Jonathan

Originally posted by JonathansCorner
Followup question: How, in the uninstaller, do I delete the registry key or part of key created as quoted above?

Thanks,
Jonathan
According to the NSIS user manual section 4.9.2.4 it should be something like this:
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "${_APP_NAME}"

Originally posted by AaronLS
According to the NSIS user manual section 4.9.2.4 it should be something like this:
DeleteRegValue HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "${_APP_NAME}"
Thank you!

Much appreciated,