Creating a registry entry to run a program at login

If you wish to have a program run whenever a user logs into the system, then you can add an entry to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run in the Windows Registry, assuming you are logged into the system as the user for which you wish to have the program run at logon at the time you add the entry to the registry, so that HKEY_CURRENT_USER (HKCU), which applies to the currently logged in user, applies to that user's account.

One way you can add a new entry in the registry for a program to run when the user logs in is to use the regedit program that comes with the Windows operating system and which is normally found in the C:\Windows directory.

E.g., let's assume you want a program called "Count" to start automatically when the user logs on. You can run the regedit registry editor and go to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run.

regedit - run key

You could then click on "Edit", then "New" and select "String Value". You could then change the name to "Count" or whatever you like. Then you would double-click on the key name you just picked to modify the value of the key. For "Value data", you would put in the path to the executable file, e.g., "C:\Program Files\Counting\count.exe". Then that program would run every time the user logs into the system.

If you need to create an entry like the one for an account that you aren't logged in under, then you need to know the Security Identifier (SID) for the account. You can determine the SID using determine-sid.vbs, a VBScript.

You can run the script using a graphical user interface (GUI) by just double-clicking on it and providing the user name for the account and either a computer name or Windows domain name when prompted. You can run it from a command prompt using cscript. Provide the name of the account and the computer name or Windows domain name on the command line. E.g., if I wanted to find the SID for the Lucy account in the domain Midland, I could use the following comand:

C:\Program Files\Scripts>cscript /nologo determine-sid.vbs Lucy Midland
Userid:               Lucy
Computer Name/Domain: Midland
SID:                  S-1-5-21-3084690208-3888753220-1328190817-1115

Once you know the SID, you could use it, instead of HKCU, so that you can create an appropriate registry entry without being logged into the user's account, if you have administrator access on the system. E.g., for the SID in the above example, the relevant registry key would be at HKEY_USERS\S-1-5-21-3084690208-3888753220-1328190817-1115\Software\Microsoft\Windows\CurrentVersion\Run. You could create an appropriate registry key using regedit as explained above or you could create it from a command prompt using a reg add command. E.g., for the example above, I could enter the following command at a command prompt:

reg add "HKEY_USERS\S-1-5-21-3084690208-3888753220-1328190817-1115\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Count" /t REG_SZ /d "\"C:\Program Files\Counting\count.exe\""

You would substitute the SID for the account for which you wished to add the registry entry instead of the one in the example. Or, if you are running the command from the account for which you wish to create the registry entry, you would use reg add "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Count" /t REG_SZ /d "\"C:\Program Files\Counting\count.exe\""

The /v option is the value for the name you wish to use for the registry key. The /t option is the type of registry entry you wish to have created and the /d argument specifies the data you wish to use for the registry key. I put two double quotes around the data and preceded the inner ones with a backslash, which serves as an escape character, so I can have double quotes inserted around the entry in the registry.

If you, instead, want to use a .REG file to create the entry, you could put the following in the .reg file, substituting HKEY_USERS\SID where SID is the relevant SID. E.g., HKEY_USERS\S-1-5-21-3084690208-3888753220-1328190817-1115 with an appropriate SID rather than the example one, if you are logged in under a different account than the one for which you wish to create the entry rather than HKEY_CURRENT_USER

 Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run]
"Count"="\"C:\\Program Files\\Counting\\count.exe\""

To add the entry to the registry, you could simply double-click on the .reg file from the Windows File Explorer.

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px