Some commands do seem to work better with a little timeout delay after they been used. WMIC calls can screw up if no delay is used, not always but it not hurt to allow a little time for them to complete. TAKEOWN & ICACLS should'nt usually as they 'pause' the script while they in action, but i now always give a little delay 1 sec is more than enough but the timeout /T 1 is the lowest 1 second amount it allows. You could use the old 'ping -n 1 -w 300 127.0.0.1 >NUL 2>&1' way but timeout looks better. That ping example is 300th of a second give or take.
Mind showing me an example of the structure of the oobe file i should have or how i would format it to use in in setup complete? I'm only guessing at it and have no idea if i'm formatting it correctly. I posted above what i did to my oobe.cmd file, does that look right? I've tried it multiple ways now none of them worked so i must be doing something wrong.
Well i not use oobe it self, the defaultuser0 routine is now part of the add-ons within the MRP. The above code is the same as what is in the addon i use, although the only thing missing is the oobestate and REM's as MRP is running in OOBE ie SYSTEM mode so full access rights are there, beyond even a Administrator. Spoiler: Code from MRP (edited log output as not needed) Code: @echo off REM Rename Registered Owner To Users Name. [ W10/Server 2016 ] Subroutine Section. Reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "RegisteredOwner" /f >nul 2>&1 Reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "RegisteredOwner" /t REG_SZ /d "%UserName%" /f >nul 2>&1 IF EXIST "%SystemDrive%\Users\defaultuser0\" GOTO :RemDU0 GOTO :Finish :RemDU0 SET UserToRemove="defaultuser0" FOR /f "tokens=*" %%a IN ('REG query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"^|find /i "s-1-5-21"') DO CALL :ChkRegistry "%%a" GOTO :Finish :ChkRegistry FOR /f "tokens=3" %%g in ('reg query %1 /v ProfileImagePath') DO SET UserProfilePath=%%g FOR /f "tokens=3 delims=\" %%e in ('echo %UserProfilePath%') DO SET ProfileName=%%e FOR /f "tokens=1 delims=." %%f IN ('echo %ProfileName%') DO SET ParseRegistry=%%f ECHO %UserToRemove%|find /I "%ParseRegistry%" >NUL IF ERRORLEVEL 1 GOTO :Dun RMDIR "%SystemDrive%\Users\%ProfileName%" /s /q >NUL 2>&1 REG delete %1 /f >NUL 2>&1 TIMEOUT /T 1 /NOBREAK >nul IF EXIST "%SystemDrive%\Users\defaultuser0\" GOTO :RetryDirRemove GOTO :Dun :RetryDirRemove TAKEOWN /F "%SystemDrive%\Users\%ProfileName%" >NUL 2>&1 ICACLS "%SystemDrive%\Users\%ProfileName%" /GRANT *S-1-1-0:F >NUL 2>&1 RMDIR "%SystemDrive%\Users\%ProfileName%" /s /q >NUL 2>&1 TIMEOUT /T 1 /NOBREAK >nul GOTO :Dun :Finish REM Proper End of script... This self-deletes this batch file. DEL /F /Q %0% >nul :Dun REM Nothing End Of Script. DO NOT DELETE OR EDIT THIS LINE! - Used for subroutine. Save the above as UserZeroRem.cmd and place in the scripts folder alongside the oobe.cmd. In your oobe.cmd , if you add: Code: IF EXIST "%windir%\Setup\scripts\UserZeroRem.cmd" CALL "%windir%\Setup\Scripts\UserZeroRem.cmd" That should do it, other than that i am unsure what is going wrong. You can change the UserZeroRem.cmd to whatever name you wish as long as the filename in the CALL .... is the same. Use .cmd and not .bat as that can cause some odd effects in oobe mode. If the above file is used on a OS other than Windows 10 RS1+2 / Server 2016 you might screw up the OS's user profile list. In the Multi-Oem/Retail Project (Continued), there are multiple checks for OS version etc that will safely remove the defaultuser0 and not cause any problems to other OS's. It brands and legally activates via SLIC (win7/Vista) or MSDM (W8.x/10) if that is available. You can still edit the Oobe with your tweaks etc but note that the username or the registry (HKCU) User Hive in the registry is NOT created at that point, oobe.cmd runs BEFORE the user is setup in the Windows Setup program. SetupComplete i think runs just after OOBE.cmd ie after the user name/registry (HKCU) User Hive is created.
This should read -- Note: Must be run as Administrator! No real criticism, but the conjugation is incorrect.
Well i was doing it both way, i guess it's just not going to work for me. Spent all night last night and a few hours today and made like a dozen isos ( with some other stuff i was working out as well, not just that ) But that's the last thing that just won't work for me. Well, it's easy enough to remove after the fact so i might just stick with that. By the way the script still doesn't actually remove defaultuser0 completely if you run it with admin rights after install, defaultuser0 is still there just disabled. It shows up in a net users command and also in lusrmgr.msc. You can delete it there and then clean up the registry as well, as there is still a lot of references to it. Which is basically how i was doing it before manually anyway. At least on my end that's what is happening. Anyway, thanks for your time and help, i've at least learned some stuff just messing around in that setup folder i knew nothing about before, so that's good.
Open Local Users and Groups, and click/tap on the Users folder in the left pane to open it. defaultuser0 ? NET.exe user defaultuser0 /delete
You might wanna look at VBS 'shell.application' object to automatically run your script as privileged user. You can test some command that succeeds on correct privileges, such as 'FSUTIL dirty query' and otherwise fails. Take a look at my script for elevation code that can run from Batch file without extracting and additionally supports passing arguments with special characters.