So, once I got Computer Naming and Domain Binding automated through the magical awesomeness that is MySysPrep2 (I STRONGLY recommend – this guy is great), I wanted to continue down the road to full automation or at least having a ready-to-use system by the time “Press Ctrl+Alt+Del to Login” showed up. In essence, I did not want to have to log in and do anything manually for our imaging.
So, this led to the SetupComplete.cmd file I made here. Basically, to make it work, just copy/paste the code into Notepad, make the modifications necessary for your environment, name it “SetupComplete.cmd”, then place it in the c:\Windows\Setup\Scripts folder and it will only run once, when Sysprep is unbundling itself.
This script does a few things – first, it checks to see if the system is on the domain. If it is, then it checks to make sure the machine has a valid IP number (in the case of my workplace, it must start with 149.84). Passing these checks leads to the portion where you can set admins, comma-deliminated. After that, it checks to see if Office is activated (since Sysprep resets the activation) and if it isn’t, it makes the attempt (we don’t have a KMS server). Lastly, it wipes the sysprep unattend file.
Obviously, this is very targeted at my specific work environment, however, it can be tweaked and modified endlessly. The real hitch is the fact that SetupComplete.cmd does not run in the foreground, so any user interaction at all has to take place via a VBS popup. Feel free to give it a try and let me know what you think!
@ECHO OFF :DOMAINCHECK FOR /F "tokens=1* delims=REG_SZ " %%O IN ('REG QUERY HKLM\System\CurrentControlSet\Services\Tcpip\Parameters /v Domain') DO ( SET CURR_DOMAIN=%%P ) IF "[%CURR_DOMAIN%]" == "[yourdomain.com]" GOTO IPCHECK GOTO DOMAINFAIL :DOMAINFAIL >domainfail.vbs echo wsh.echo msgbox ("System did not join the domain. Remainder of setup must be done manually.",0,"Domain Join Error") cscript domainfail.vbs > NUL GOTO EXIT :IPCHECK del /F /Q ipfailed.vbs > NUL cls ipconfig|find /I "IPv4"|find /I "149.84" > NUL IF ERRORLEVEL=1 GOTO IPFAILED IF ERRORLEVEL=0 GOTO ADMINUSER :IPFAILED FOR /F "tokens=14" %%N IN ('ipconfig^|find /I "IPv4"^') DO SET IPADD=%%N >ipfailed.vbs echo wsh.echo msgbox ("Alfred network not found. Your current IP number is %IPADD%. Please connect the network cable and try again",5,"Network Error") for /f "tokens=*" %%M in ('cscript ipfailed.vbs') DO SET IPFAILEDRESP=%%M IF "[%IPFAILEDRESP%]" == "[2]" GOTO EXIT IF "[%IPFAILEDRESP%]" == "[4]" GOTO IPCHECK :ADMINUSER >admins.vbs echo wsh.echo inputbox ("Domain user to set as admin: (for multiples names, separate each entry with a comma - limit 10)",0,"Set Administrators") for /f "tokens=1,2,3,4,5,6,7,8,9,10 delims=," %%A in ('cscript admins.vbs') DO @( SET USER1=%%A SET USER2=%%B SET USER3=%%C SET USER4=%%D SET USER5=%%E SET USER6=%%F SET USER7=%%G SET USER8=%%H SET USER9=%%I SET USER10=%%J ) GOTO USERCHECK :USERCHECK echo %%A|find /I "Microsoft" > NUL IF ERRORLEVEL=1 GOTO USER1 IF ERRORLEVEL=0 GOTO OFFICEACT :USER1 IF "[%USER1%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER1% /add GOTO USER2 :USER2 IF "[%USER2%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER2% /add GOTO USER3 :USER3 IF "[%USER3%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER3% /add GOTO USER4 :USER4 IF "[%USER4%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER4% /add GOTO USER5 :USER5 IF "[%USER5%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER5% /add GOTO USER6 :USER6 IF "[%USER6%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER6% /add GOTO USER7 :USER7 IF "[%USER7%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER7% /add GOTO USER8 :USER8 IF "[%USER8%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER8% /add GOTO USER9 :USER9 IF "[%USER9%]" == "[]" GOTO OFFICEACT net localgroup administrators YOURDOMAIN\%USER9% /add GOTO USER10 :USER10 net localgroup administrators YOURDOMAIN\%USER10% /add GOTO OFFICEACT :OFFICEACT cscript "c:\Program Files\Microsoft Office\Office14\OSPP.VBS" /dstatus|find /I "---LICENSED---" > NUL IF ERRORLEVEL=1 GOTO OFFACTIVATE IF ERRORLEVEL=0 GOTO EXIT GOTO EXIT :OFFACTIVATE cscript "c:\Program Files\Microsoft Office\Office14\OSPP.VBS" /osppsvcauto > NUL cscript "c:\Program Files\Microsoft Office\Office14\OSPP.VBS" /act > NUL GOTO VERIFY :VERIFY cscript "c:\Program Files\Microsoft Office\Office14\OSPP.VBS" /dstatus|find /I "---LICENSED---" > NUL IF ERRORLEVEL=1 GOTO FAILED IF ERRORLEVEL=0 GOTO EXIT :FAILED ECHO Office activation failed. > c:\offact.txt GOTO EXIT :EXIT del /F /Q domainfail.vbs del /F /Q ipfailed.vbs del /F /Q admins.vbs del /F /Q c:\unattend.xml exit
It’s amazing designed for me to have a website, which is good designed
for my know-how. thanks admin