Auto run action when a new user loges on / add setting to HKEY_CURRENT_USER

Ever wanted to set a registry key to automate some stuff for your users, only to find out that the key resides in HKEY_CURRENT_USER making it quit difficult to have it work for all users on the pc. You can of cause set this in your login script, but setting registry fixes is not really a job for the login script.

During a deployment scenario, where only the administrator is logged in, we can obviously us the run once command from the registry, but that only run once on the computer, and not once pr. USER. We could also manipulate the NTUSER.DAT file and add settings there, but not all settings from ntuser.dat is transferred to the current user.

What we could do is to create an entry in the “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components” key. Basically the entrees in this key is the stuff you se in the upper left hand corner during first log on. (the Personalized Settings box). Most if not all entries in this key will be in the GUID format, but it does not have to be..

Open REGEDIT and follow the instructions below.

image Right click Installed Components and click New KEY, and name the key {Z-UserSetup}.

NOTE: The different keys are executed in number and alphabetical order, so to make sure our key is executed last we name it Z-“something” and put it in { }. Everything not in curly braces wile be executed first.

image In the new key create two new String Values (REG_SZ) and name them
StubPath and
Version.

StubPath has info on what we want to run, and could be any executable, script, run.dll e.t.c.

Version will show in the Installed Components section in CURRENT_USER

(Default) will be the info showed in the Personalized settings box during logon. (can also be sat as @=”info”)

 

Now just reboot and log on with a different user, and notepad will be executed during logon.

If you want to set this with a script ,then here small one for disabling the Windows Media Player wizard.

Set oShell = CreateObject("WScript.Shell") 

RegPath="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{Z-UserSetup}\"
oshell.RegWrite Regpath & "Stubpath", "reg.exe add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences" _
& "/v AcceptedPrivacyStatement /t REG_DWORD /d 1 /f", "REG_SZ"
oshell.RegWrite Regpath & "Version", "1.00", "REG_SZ"
oshell.RegWrite Regpath & "@", "Accept MP Privacy Statement", "REG_SZ" 

You can add as many entrees as you want, just be aware of the execution order.


Comments (8):

  1. Ah thanks so much Michael, was trying to find a way to do this sort of ‘Run Once’ ordeal purely for new users. This was it, and exactly the same problem I was trying to solve (WMP Privacy). I had a bit of trouble finding this post from the last one which mentioned Active Setup, but google helped out.

    Thanks!

  2. Paul B. says:

    Hi Michael

    Thanks for the script, but I’m still having a little trouble.
    (32bit windows 7 client)
    Any ideas as to what I’m doing wrong. When I run your script it adds your registry entries fine, but when I run Media Player the welcome wizard still appears. On checking the registry HKCU\software\microsoft\preferences\AcceptedPrivacyStatment the value is still 0

    any ideas?

  3. Paul, just to be sure — you are creating a *new* user afterwards and logging into that one correct? This script will not adjust any existing users.

  4. Fantastisk !!!

    Tak Michael – dette har sparet mig for mange timers arbejde.

    Mvh
    Martin Warner

  5. Ricardo says:

    Hi Michael,

    Thank you for the information provided. Im running (Windows 7 Professional) the script which generates the following error:

    WshShell.RegWrite (6, 1) : Invalid root in registry key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{Z-UserSetup}\Stubpath”.

    Any Idea ?

    Thank you very much

  6. Ricardo says:

    Hi Michael, It’s me again, I just wanted to post the script I have which generates the error mentioned before.

    Set oShell = CreateObject(“WScript.Shell”)

    RegPath=”HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{Z-UserSetup}\”

    oshell.RegWrite Regpath & “Stubpath”, “reg.exe add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences /v AcceptedPrivacyStatement /t REG_DWORD /d 1 /f”, “REG_SZ”
    oshell.RegWrite Regpath & “Stubpath”, “reg.exe add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences /v AcceptedEULA /t REG_DWORD /d 1 /f”, “REG_SZ”
    oshell.RegWrite Regpath & “Stubpath”, “reg.exe add HKCU\SOFTWARE\Microsoft\MediaPlayer\Preferences /v FirstRun /t REG_DWORD /d 0 /f”, “REG_SZ”
    oshell.RegWrite Regpath & “Version”, “1.00″, “REG_SZ”
    oshell.RegWrite Regpath & “@”, “Accept MP Privacy Statement”, “REG_SZ”

  7. Jim Achuff says:

    Ricardo,

    You have to execute the script as a local administrator or else it can’t create the key.

    Good Luck.

    –Jim

Leave a Reply

(required)