Runonce for default user profile, can it be scripted?

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Runonce for default user profile, can it be scripted?

Post by MigrationUser »

11 May 2008 02:13
NDog


Hi. I am trying to create a value in the default user profile runonce to point at a login script.

This means that when you create a new user profile in xp, the runonce script will execute when the user first logs in.

As far as I am aware, this process can not be done by script, but only manually, like this.

01) open regedit
02) go to HKEY_USERS
03) Load Hive
04) Browse to C:\Documents and Settings\Default User\ntuser.dat
05) give it a temporary key name, for example ZZZ
06) go to HKEY_USERS\ZZZ\Software\Microsoft\Windows\CurrentVersion
07) Create a key RunOnce
08) Create a string value there eg: First Run, then change the value to where your script sits, eg: "D:\User\zxp\newUserProfile.cmd"
09) go back to HKEY_USERS\ZZZ
10) unload the hive

Now when you create a new user, the runonce value runs on the first login so you can run a first time user script; eg newUserProfile.cmd

The script below is only for illustrative purposes. but if anyone knows how i can add in a registry value into the different user hive by script, rather than manually, that will be cool, and a great time saver :pc:

Thanks :D

newUserProfile.cmd

Code: Select all

@echo off&cls
title=%~n0

:: Stored @
:: D:\User\zXP\newUserProfile.cmd
::

taskkill /f /im explorer.exe

::
:: Create User Folder on data partition
::

echo Setting up your user profile for first time use ...

:: Set location where the users files will save to (NOT on systemdrive)
set _userstore=D:\User

set _desktop=%_userstore%\%USERNAME%\Desktop
set _favorites=%_userstore%\%USERNAME%\Favorites
set _mydocuments=%_userstore%\%USERNAME%\My Documents
set _mymusic=%_userstore%\%USERNAME%\My Documents\My Music
set _mypictures=%_userstore%\%USERNAME%\My Documents\My Pictures
set _myvideo=%_userstore%\%USERNAME%\My Documents\My Video
md "%_desktop%"
md "%_favorites%"
md "%_mydocuments%"
md "%_mymusic%"
md "%_mypictures%"
md "%_myvideo%"

:: Update registry to point @ the user folders
set _regusf=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
reg add "%_regusf%" /v Desktop /t REG_EXPAND_SZ /d "%_desktop%" /f
reg add "%_regusf%" /v Favorites /t REG_EXPAND_SZ /d "%_favorites%" /f
reg add "%_regusf%" /v Personal /t REG_EXPAND_SZ /d "%_mydocuments%" /f
reg add "%_regusf%" /v My Music /t REG_EXPAND_SZ /d "%_mymusic%" /f
reg add "%_regusf%" /v My Pictures /t REG_EXPAND_SZ /d "%_mypictures%" /f
reg add "%_regusf%" /v My Video /t REG_EXPAND_SZ /d "%_myvideo%" /f

:: Restart explorer.exe so changes are immediate

start explorer.exe

:: Remove unneccesary user profile folders on systemdrive
rd /s /q "%USERPROFILE%\Favorites"
rd /s /q "%USERPROFILE%\My Documents"
rd /s /q "%USERPROFILE%\My Music"
rd /s /q "%USERPROFILE%\My Pictures"
rd /s /q "%USERPROFILE%\My Video"

::
:: UI Tweaks
::

::
:: Files Cleanup
::

del /q "%windir%\*.log"
del /q "%windir%\*.tmp"
del /q "%windir%\Temp\*.*"

::
:: Services
::

net stop "wuauserv"

sc config "Alerter" start= disabled
sc config "browser" start= disabled
sc config "messenger" start= disabled
sc config "upnphost" start= disabled
sc config "wuauserv" start= disabled

::
:: Restrictions
::
cmd, vbs, ps, bash
autoit, python, swift

----------------------------

#11 May 2008 13:06
bluesxman


OK I think I understand what you're up to. I have a couple of thoughts on the matter (bearing in mind I've not tested either) ...

You might try using "psgetsid", available from the website formerly known as Sysinternals (latterly Borged by Microsoft), to figure out the SID of the new user account. You can then (probably) do what you want to do with by using the REG command to address "HKU\<User SID>\Software\Microsoft\Windows\CurrentVersion\RunOnce".

Or, more straightforwardly, why not just drop the "RunOnce" thing into the Default User registry by addressing "HKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\RunOnce", again with the REG command?

Last edited by bluesxman (12 May 2008 11:03)

cmd | *sh | ruby | chef

----------------------------

#11 May 2008 18:42
Simon Sheppard


If this is on a domain, then you can just customize one 'Default User' and copy it to the Netlogon share of the Domain Controller.

see Q168475
http://support.microsoft.com/kb/168475 {dead link}

Alternatively apply a System Policy to change the registry settings.

----------------------------

#17 May 2008 22:04
NDog


Thanks for the suggestions guys, but this is not possible by dropping into hku.default (i already thought of that, and double checked it after the suggestions) and its not on a domain (i dont use those )
I am going to try something like autoit to automate it instead or ask somewhere else cool

cmd, vbs, ps, bash
autoit, python, swift

----------------------------

#19 May 2008 11:13
bluesxman


No luck with the "psgetsid" thing then?

cmd | *sh | ruby | chef

----------------------------

#19 May 2008 21:48
Warey


I use a small utility called modifyprofile.exe which loads the Default User registry hive and applies changes to it through importing a .reg file. It then unloads it when the command is complete.

I'm not at work at the moment, and I can't remember where I found it, but a quick Google for modifyprofile.exe should do the trick. wink

----------------------------

#28 May 2008 10:14
NDog


Thanks Warey that cmd-line program works exactly what I need.
I will post how I got it working to wrap up the thread and help anyone who stumbles upon this thread.

Download Modify Profile v1.21 (ModifyProfile.exe) http://www.optimumx.com/download/#ModifyProfile

Create a folder and put ModifyProfile.exe in it and create 2 files in it; import.reg & loadhkdu.cmd

loadhkdu.cmd

Code: Select all

ModifyProfile.exe /PROFILE:"C:\Documents and Settings\Default User\NTUser.dat" /REG:%cd%\import.reg /KEYNAME:ZZZ
import.reg

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_USERS\ZZZ\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce]
"newUserProfile"="\"D:\\User\\zxp\\newUserProfile.cmd\""
Run loadhkdu.cmd
That does the trick! Thanks! lol

Now every time you create a new user in XP they will have a this startup script run when they first log in!

EDIT - I just found this by googling this forum how ironic

loadhkdu2.cmd

Code: Select all

[b]reg load[/b] HKU\ZZZ "C:\Documents and Settings\Default User\NTUSER.DAT"
REG ADD HKU\ZZZ\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce /v newUserProfile /t REG_EXPAND_SZ /d "D:\User\zxp\newUserProfile.cmd" /f
reg unload HKU\ZZZ
That will ALSO do the trick. lol.

Last edited by NDog (28 May 2008 10:51)

cmd, vbs, ps, bash
autoit, python, swift

----------------------------

#28 May 2008 11:25
bluesxman


"REG LOAD" you say? D'oh, d'oh, d'oh!

cmd | *sh | ruby | chef

----------------------------

#31 May 2008 17:55
Simon Sheppard


OK this has prompted me to update the REG page with some examples.
Post Reply