Friday, March 13, 2009

How to create a .profile/.login file in Windows XP

In the Unix world, a script is run every time you log in. The exact file depends on the type of shell. For example, tcsh uses the .login file, while sh and bash use .profile. But on windows, if there is something I want to run at startup, I just add it to the 'Startup' folder in the Programs menu.

But, in some cases, I want to run a set of commands, but I don't want it to be in the 'Startup' folder where it can be run again by just clicking it. I want to be able to execute certain commands at login without putting them in the 'Startup' folder.

This is actually quite simple. Just create the file %USERPROFILE%\login.cmd. That file will be executed automatically when you log in.

This is similar to my post about sourcing a file when you start a command shell. The difference with that is that it only applies to the command console and it is sourced for every cmd.exe shell you start, whereas the login.cmd file is loaded only once at login by Windows.

No comments: