How to Create a Runonce Script
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.
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
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.
Click the Windows \"Start\" button and select \"Run.\" Type \"regedt32\" and press enter.
Click the \"HKEY_USERS\" directory on the left. From the \"Registry\" menu, select \"Load Hive.\"
Navigate to the \"HKEY_USERS\\Test\\Software\\Microsoft\\Windows\\CurrentVersion\\Runonce\" directory in the registry.
Right-click the \"Runonce\" directory and select \"Add Value.\" This opens a window that prompts you for the values of your .bat script.
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.
Select \"Unload hive\" from the \"Registry\" menu item.
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.