Technology Musings
If you’re like me and need multiple programs to start upon login, your hard drive is likely inundated with requests, causing a major slowdown as the OS seeks to fill each and every request simultaneously. Furthermore, I have some programs that are dependent upon others, so when they load out of order, I have to shutdown and restart the applications or perform some extra steps to reconfigure the program. An example of this is synchronizing DropBox and ZumoDrive. If DropBox starts before ZumoDrive, it never syncs and hangs in an “Indexing…” state. This matter is complicated by storing my KeePass database on my ZumoDrive. Because KeePass loads before ZumoDrive, it can’t find the Z: location and I have to re-locate the KDB file for it to load.
One solution to this problem is to start the programs manually, which is monotonous. A much better solution is to control the exact startup sequence, giving each program a small delay to fully load before starting the next program. A solution I used in the past for Windows was a batch file. This suffers from a couple of problems:
To overcome these issues, I took a gander at my latest favorite scripting language, PowerShell; it handily solves both issues. This is a very easy hack and to accomplish it, there are only a few steps. The only considerations for this project is to ensure that PowerShell v1 or v2 is installed and configured to run scripts locally. With those assumptions, let’s get started:
Let’s get directly to the fun stuff. Because we’re only performing 2 types of actions, the script itself is actually very simple. The hardest part of this step is locating each program. Create a new PowerShell script called Startup.ps1 and save it in your (My) Documents folder. Copy my example script to get started:
Start-Sleep –s 15 & 'C:\Program Files\Zecter\ZumoDrive\zumodrive.exe' Start-Sleep –s 5 & 'C:\Program Files\Dropbox\Dropbox.exe' /home Start-Sleep –s 5 & 'C:\Program Files\Digsby\Digsby.exe' Start-Sleep –s 15 & 'C:\Program Files\KeePass Password Safe\KeePass.exe'
The Start-Sleep command suspends the script for a specific amount of time. By specifying the “-s 15″ parameter, we provide a delay of 15 seconds. I provide an initial delay on load of the script simply to ensure the OS has loaded other necessary modules.
The second type of line is the actual execution of a program. The command is an ampersand (&) followed by the program path enclosed in single quotes. Any program parameters can go after the path name. The use of single quotes (') indicates we are passing a literal string. If we were to use double-quotes instead, PowerShell would attempt to interpret any variables enclosed, of which we have none.
Cofigure your script with the programs you want started at logon. A good solution to this is to check the properties of each program in your start menu. For anything not in your Start Menu, you’ll have to locate the application. We’ll test the script a bit later.
This step is a bit more complicated, because you may need to go into each program and turn off the “Automatically start when I log on to Windows” option. A quick way to head off most of these issues is through the msconfig tool. Simply start msconfig (XP: Start→Run→msconfig. Vista: Start→mscofig).
Switch to the Startup tab and uncheck items you plan to load through your custom logon script. When done, click “OK”.
The final step is to actually enable the startup script. Navigate to your Startup program folder. The easiest way to accomplish this is to find the Startup folder in your Start Menu, Right-click, and select “Open”.
A new folder will open and you want to create a new shortcut here. Right-click in an empty spot in the folder and choose New→Shortcut.
A Wizard will open prompting your for the location of the item. In the text box, put “powershell .\Startup.ps1″.
Technically, you can provide the absolute path to the item, but we’ll utilize a slightly different method. Click “Next” and name the shortcut to your liking, maybe, “Default Startup”.
When the wizard closes, switch back to the Startup folder and you should see your new shortcut. Right-click the shortcut and select “Properties”.
Take note that the “Target” field has been expanded to the full path to PowerShell. For example, “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe .\Startup.ps1″. We want to edit the field directly below it, labeled “Start in”. Delete the contents of the field and replace it with "%USERPROFILE%\Documents" for Vista or "%USERPROFILE%\My Documents". Go ahead and include double-quotes just for completeness. When done, click “OK”.
When you’re done, it’s best to exit all the programs and run the script, ensuring there are no errors. To correctly configure the delay times, you may want to reboot, which ensures the memory cache is clear. You can then jot down which programs need more or less time.
To test, simply double-click the shortcut. If all goes according to plan, all your programs should launch just as before. And because the shortcut it located in the Startup folder, this should happen each time you log in to your profile.
For me, this is a great, simple solution using a tool I already have installed on my computer. Additionally, as my needs change, it gives me ultimate flexibility in the future. I could even go so far as to conditionally launch programs depending on aspects like date and time.
3 Responses to Control Startup Program Order with PowerShell
Alexy
April 18th, 2009 at 6:42 pm
Very nice! Interestingly, I moved my Program Files folders to a B: drive by editing the registry, ProgramFilesDir => B:\Applications, and now trying to click Change Startup Options from Control Panel=>Programs fails, saying “Windows cannot find B:\Applications\windows”. Perhaps it’s looking for C:\Windows\win.ini? So that also must be taken into account! As well as the question whether it’s good to supress startup via msconfig — will it leave any registry settings for those programs believing they are starting up, or it does clear the Run in registry?
Jim
July 6th, 2009 at 3:40 pm
Removing out of the MSConfig will keep the from starting regardless of registry settings. The only problem I have heard but have not confirmed is that if you uninstall one of those apps you may not get a clean uninstall and thus have a dirty registry that might cause problems later.
Solution is to check them all on again when you install or uninstall apps. Hmmm maybe a powershell script can be created for shutting those off and on again. Oh well.
Jen McCown
August 20th, 2009 at 8:00 am
Thanks, this is exactly what I was looking for! We’re making free PowerShell (and other) training vids for our site; I’d like to make one on this topic & give you a credit. -Jen