How to Create a Runonce Script

By Lysis

A \"runonce\" script is a file that is run from the \"runonce\" section of the Windows registry. The format is a .bat file that has lines of code to run a program only once. For instance, you may want to load a program the next time a user logs into the computer. The process to create a runonce file is to create the .bat file and enter it into the Windows registry. This example shows you how to create a .bat file and install it into the Windows registry.

Step 1

Create the .bat file by opening Notepad and entering simple syntax commands. For this example, the .bat file will run an instance of Notepad when the user starts the computer. Use the following lines to create the .bat file.@echo offc:\\system32\\notepad.exeexit

Step 2

Save the .bat file as \"C:\\myservice\\mystartup.bat\" directory. Notepad saves files with the extension of .txt, so right-click the file and rename the txt extension to bat.

Step 3

Click the Windows \"Start\" button and select \"Run.\" Type \"regedt32\" and press enter.

Step 4

Click the \"HKEY_USERS\" directory on the left. From the \"Registry\" menu, select \"Load Hive.\"

Step 5

Navigate to the \"HKEY_USERS\\Test\\Software\\Microsoft\\Windows\\CurrentVersion\\Runonce\" directory in the registry.

Step 6

Right-click the \"Runonce\" directory and select \"Add Value.\" This opens a window that prompts you for the values of your .bat script.

Step 7

Enter the information of the runonce file. Enter \"My Program\" in the \"Value name\" section. Select \"REG_SZ\" for the type and enter the location of the bat file. For this example, enter \"C:\\myservice\\mystartup.bat\" for the location.

Step 8

Select \"Unload hive\" from the \"Registry\" menu item.

Step 9

Reboot the computer. When you login, the Notepad application runs. If you reboot the computer again, it will not run. A runonce script only runs the first time the machine is booted after its installation.

References & Resources