I couldnt get sysprep copyprofile to work with my image so i am trying to find a different method of doing this.
What was the issue with Sysprep? Maybe we could help you finding a solution for that.
I'm asking because the easiest and recommend way to do this is to do it in Audit Mode, Sysprep with CopyProfile set to TRUE. Open Notepad, type your commands and add del %0
as last command line. That takes care of deleting the batch when it's run. Save the file as a .bat in %appdata%\Microsoft\Windows\Start Menu\Programs\Startup
.
I usually name these batches I want to be run only once whenever a new user signs in first time as RunOnce.bat.
When done, run Sysprep. Remember that for CopyProfile to work you must use the /generalize switch with Sysprep command, for instance to run Sysprep and shutdown to be able to capture the Windows image, you would use the following command:
%windir%\system32\sysprep\sysprep.exe /generalize /oobe /unattend:W:\YourAnswerFile.xml
/unattend:AnswerFilePathAndName.xml is optional; if you save the answer file as unattend.xml in C:\Windows\System32\Sysprep folder, it will be automatically used. If you name the answer file to something else, or save it to another location, use /unattend switch.
That's it.
I'll add a sample RunOnce.bat below, you can just copy and modify it according to your needs. This sample batch would set screensaver active (enabled) setting the value of string (REG_SZ) ScreenSaveActive to 1, and force user to enter password when resumed from screensaver by setting the value of string ScreenSaverIsSecure to 1. Both strings are in key HKEY_CURRENT_USER\Control Panel\Desktop. When new user signs in first time, the batch will be run and deleted so it only runs once for each new user:
Code:
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaveActive /d "1" /t REG_SZ /f
reg add "HKEY_CURRENT_USER\Control Panel\Desktop" /v ScreenSaverIsSecure /d "1" /t REG_SZ /f
del %0
(Please notice, there are no typos in above batch sample. First string uses label ScreenSave, the second ScreenSaver.)
Syntax of reg add command:
reg add "Key Name" /v ValueName /d "Value" /t DataType /f
Valid data types:
- REG_SZ = String value
- REG_MULTI_SZ = Multi-string value
- REG_EXPAND_SZ = Expandable string value
- REG_DWORD = DWORD 32 bit value
- REG_QWORD = QWORD 64 bit value
- REG_BINARY = Binary value
The /f
switch forces writing the new value without prompting the user.
Last but not least, if you want this batch to be run only once when first initial user signs in to Windows, but not later when additional users sign in, save the batch in %programdata%\Microsoft\Windows\Start Menu\Programs\Startup
instead of %appdata%
.
You can get the batch file to delete itself by putting a del command on the last line of the batch file.
DEL alone is not enough. Name of current batch process is stored in variable %0, the last line of batch should therefore be del %0
.
Kari