Getting a Script to Run Once for a New User (In Windows)
LIKE ?

  • Share

I have recently be working on a project to implement a WDS set up for the company I am currently supporting.  One of the problems I came up against is that their IT Director wanted Google Chrome installed on all machines.  The problem with this is that Chrome installs itself to the %USERPROFILE% location instead of Program Files like other software.  This means that the software has to be reinstalled for every user who logs on to a desktop although it does mean that admin rights are not required to install it.

As I did not want to have to manually install this separately for every user I managed to set it so that the Google Online Installer would run every time an new user logged on to a machine.  This also had the added advantage of being a good method of running a script to restore Outlook Data such as NK2 and Signatures from a backup on shared drive when a new user logged on. (I will hopefully be doing a post on my outlook scripts soon).

I have used this little trick on Windows XP as that is what this office is working with but it should also work on Vista and Win 7.

The First Step is to load the registry editor by typing REGEDIT at the RUN prompt, (or the Vista/Win 7 Search box).  In the left pane of the REGEDIT window bring the HKEY_USER hive in to focus then click on the file menu at the top and select “Load Hive” from that menu.

load-hive

 

In the “Load hive” dialog box load the Default Users “NTUSER.DAT” file from “C:\Documents and Settings\Default User\NTUSER.DAT”, you will need to have “Show hidden files and folders” turned on to be able to locate this file.  (The location of this file will be different on Vista/Win7, Under the Users directory instead of Documents and Settings).  This is the folder the registry settings are loaded from when a new user is created on the system.

open

 

You will now get a dialog box to name the new Hive.  You can give it any name then click OK.

name

Now you can locate the Hive you just loaded in the left pane of the REGEDIT window and open it, then navigate with in the Hive to
“HKEY_USERS\[your hive name]\Software\Microsoft\Windows\CurrentVersion\”.  Then locate the “RunOnce” key here, if it doesn’t exist right click on the “CurrentVersion” key and select “New –> Key”.

newkey

Now name the new Key “RunOnce” and in that Key in the right pane, right click and select “New –> String Value”

newstring

This string you can name whatever you want but is helps to give it a meaningful name if you come back to it in the future.  Now you just need to give the string a value, right click on the string value and select “Modify” and in the “Value Data” box give the path to the file you want to run. (in my screen shot it is the Google Chrome Installer but could be any EXE or Script file.)

confstring

Finally the last step is to give focus to the top level of the Hive you imported in the left pane of the REGEDIT window then go to the file menu and select “Unload Hive”

From now on whenever a user logs on to this machine for the first time it will run whatever application you have set here then delete the registry key so it will not run again.  This will only work for users who have never logged on to this machine before.

1 COMMENT TO Getting a Script to Run Once for a New User (In Windows)

[New Post] Getting a Script to Run Once for a New User (In Windows) http://digitalsandbox.co.uk/2010/03/gett...

March 16th, 2010
davotronic5000