[SOLVED] Remove a user profile such as defaultuser0

Discussion in 'Scripting' started by mxman2k, Aug 22, 2016.

  1. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    #1 mxman2k, Aug 22, 2016
    Last edited by a moderator: Apr 20, 2017
    UPDATED

    After a few revisions and learning new batch commands here is the completed script to automate removal of the defaultuser0 cleanly and now with additional changes for the 'Windows User' glitch probably caused by this defaultuser0 'bug'.

    The new "completed" script (Must be run as Administrator if run manually, but if added or CALLed via OOBE.CMD this will be automatically run as SYSTEM.

    Code:
    REM ** Must be ran as Administrator to function correctly. **
    REM Simple script to check for defaultuser0 , correct Windows User name to account name, delete defaultuser0 files and clean up registry area.
    REM -
    REM  Designed for Windows 10 RS1/Anniversary Update.
    
    SET OobeState=0
    REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State" | findstr /I "\<IMAGE_STATE_COMPLETE\>" >nul && IF ERRORLEVEL=1 SET OobeState=1
    REM Returns - Oobestate 0 = not running via oobe.  1 = setup not complete ie within Windows setup's oobe stage.
    
    REM         add REM before, or delete the line below to allow RegisteredOwner rename via manual method if required.
    IF %OobeState%==0 GOTO :StartMain
    
    REM To change the RegisteredOwner registry entry to current username. 
    REM It has to be deleted then re-added or fails tried /ve and other ways , only delete and remake works properly??
    IF EXIST "%SystemDrive%\Users\defaultuser0\" (
    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
    )
    
    :StartMain
    SET UserToRemove="defaultuser0"
    REM 'CALL' check registry subroutine check for existance and remove.
    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
    REM -----------------------------------------------------------------------
    REM Results of ERRORLEVEL are:
    REM 0  -- If UserToRemove is found in the registry then run rest of script.
    REM 1  -- If UserToRemove is NOT found in the registry then exit script.
    REM -----------------------------------------------------------------------
    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 :Finish
    
    REM Remove that user...
    RMDIR "%SystemDrive%\Users\%ProfileName%" /s /q
    REG delete %1 /f >nul
    IF EXIST "%SystemDrive%\Users\%ProfileName%" GOTO :RetryDirRemove
    GOTO :Finish
    
    :RetryDirRemove
    TAKEOWN /F "%ProfileName%" >nul
    TIMEOUT /T 2 >nul
    ICACLS "%ProfileName%" /GRANT *S-1-1-0:F >nul
    TIMEOUT /T 2 >nul
    RMDIR "%SystemDrive%\Users\%ProfileName%" /s /q
    
    :Finish
    REM End of script...
    

    Enjoy. Any problems/questions please let me know.

    Mx



    Have left original text of this OP for reference below.
    ==Original OP below for reference how this thread progressed ==

    A good friend of mine who sadly is no longer with us (RIP Alan), put together a simple script for me to remove a single user from a computer completely. It was written for Windows 7 & 8.x, but also works on W10 too :) - he based it on another script and he has credited the website within the REM statements that he used to base this on.

    The beauty of this little gem is that it will remove the dreaded defaultuser0, as i am not very good with batch or any program writing he added a few comments within to help me try to understand how it all worked - I'm still lost lol.

    If any batch guru can edit this script so it can be used in either oobe.cmd or setupcomplete.cmd stages so that it can be fully 'automatic' would be much appreciated. The only real bit i understand is the SET UserToRemove="<username>" and have just edited that to be defaultuser0, the rest is as it was written.

    He mentioned that NET user /delete <username> should work but for some reason it does not remove everything so cobbled together this batch.

    As noted in the comments it must be ran as Administrator or it won't clear the registry bits.

    Code:
    @ECHO OFF
    COLOR 1F
    REM =======================================
    REM = Simple User Profile removal script. =
    REM =======================================
    REM Removes User specified from the registry AND the users folder.
    REM -
    REM Simple checks for current username if trying to remove currently logged in user will give error.
    REM -
    REM Please Note: This MUST be run as Administrator or it will fail to remove user from registry.
    REM -
    REM The SET UserToRemove="xxxxx" variable MUST be in quotes to allow a name with spaces etc.
    REM -
    REM Remember there is only a simple check for username in use you can seriously screw up your computer if misused.
    REM -
    REM Script design from various sources on the internet but mainly based on this script found here:
    REM https://mstoneblog.wordpress.com/2010/12/08/user-profile-cleaning-script-for-windows-7/
    REM -
    
    REM User Profile to remove MUST be in quotes. Not case sensitive. Only ONE user can be given, script is NOT recursive!
    set UserToRemove="defaultuser0"
    
    TITLE Windows %UserToRemove% Profile Cleaning...
    echo.
    
    REM 'CALL' check registry subroutine check for existance and remove. Also simple error check for currently logged in user.
    FOR /f "tokens=*" %%a IN ('REG query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList"^|find /i "s-1-5-21"') DO CALL :ChkRegistry "%%a"
    IF %ERRORLEVEL%==0 echo Script Completed.
    IF %ERRORLEVEL%==1 EXIT
    GOTO :Ex1
    
    :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 /I %UserToRemove%=="%UserName%" echo ERROR: You cannot remove your account you are logged in with^! &GOTO :Ex1
    IF ERRORLEVEL=1 GOTO :NotFound
    IF ERRORLEVEL=0 GOTO :RemoveUser
    
    :NotFound
    ECHO User Profile %UserToRemove% not found in registry.
    GOTO :Ex1
    
    :RemoveUser
    echo.
    echo WARNING: Removal IS Permanent^!  Answer yes in full or script will abort.
    echo.
    SET /P YN=ARE YOU SURE YOU WISH TO REMOVE THIS USER {Yes/No} ? || Set YN=No
    IF /I "%YN%"=="Yes" GOTO :AskAgain
    echo.
    echo Aborting.
    GOTO :Ex1
    
    :AskAgain
    echo.
    echo Checking that you are 100 percent sure you wish to delete this profile %UserToRemove% &echo.
    SET /P YN=ARE YOU SURE YOU WISH TO REMOVE THIS USER {Yes/No} ? || Set YN=No
    IF /I "%YN%"=="Yes" GOTO :OK
    echo.
    echo Aborting.
    GOTO :Ex1
    
    :OK
    echo.
    ECHO Removing %ProfileName% user folder from %SystemDrive%\Users...
    echo. 
    rmdir "%SystemDrive%\Users\%ProfileName%" /s /q
    echo.
    ECHO Cleaning registry of the %ProfileName% profile...
    echo %1 &echo.
    reg delete %1 /f >nul
    REM Check if folder deleted, if not retry with ownership.
    IF EXIST "C:\Users\%ProfileName%" GOTO :RetryDirRemove
    GOTO :EOF
    
    :RetryDirRemove
    echo.
    ECHO Retrying removal of %systemdrive%\users\%ProfileName% {Takeown Method}...
    TAKEOWN /F "%ProfileName%" >nul
    TIMEOUT /T 2 >nul
    ICACLS "%ProfileName%" /GRANT *S-1-1-0:F >nul
    TIMEOUT /T 2 >nul
    rmdir "%SystemDrive%\Users\%ProfileName%" /s /q
    echo.
    GOTO :EOF
    
    :Ex1
    echo.
    pause
    EXIT
    

    Probably someone has already written a script to automate this but searching the forum i only found info on how to do it manually, hopefully someone with better knowledge can edit this to just check if the defaultuser0 is on a system after oobe completed and remove it.

    Many thanks

    Mx
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. ofernandofilo

    ofernandofilo MDL Member

    Sep 26, 2015
    237
    140
    10
    I never saw this account. I'm brazillian, and maybe in my system the user get some other name, maybe TEMP.

    This is not the user created when Windows can not open the real user? And then the Windows create a temporary user just to you get some gui? I just never saw this. But the script seems to work ok. Thanks for sharing!

    cheers
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    The defaultuser0 account appears on some installations of the W10 anniversary, it seems to affect certain language ones not all.

    Just wanted to give something back to the forum that might be of some use :biggrin: and if the script can be edited to do the removal automatic by someone with better knowledge than my limited batch skills more the better.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    #4 KNARZ, Aug 23, 2016
    Last edited by a moderator: Apr 20, 2017
    edit this line:
    Code:
    IF ERRORLEVEL=0 GOTO :RemoveUser
    to:
    Code:
    IF ERRORLEVEL=0 GOTO :OK
    no questions ask anymore.

    The script is written good, better than most I have seen here.
     
  5. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #5 Compo, Aug 23, 2016
    Last edited by a moderator: Apr 20, 2017
    That's not how ERRORLEVEL works!
    It should be:
    Code:
    IF NOT ERRORLEVEL 1 GOTO :OK
    or:
    Code:
    IF %ERRORLEVEL%==0 GOTO :OK
    How about this in a possibly admin console window…
    Code:
    WMIC /Node:"localhost" Path Win32_UserProfile Where "Special!='True' And LocalPath Like '%defaultuser0'" Delete
    If the account is a special one then at your own risk:
    Code:
    WMIC /Node:"localhost" Path Win32_UserProfile Where "LocalPath Like '%defaultuser0'" Delete
    Untested.
     
  6. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    you are absolutly right. I didn't check on syntax just on the workflow to make it silent.
    Based on the statement that its working.
     
  7. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    #7 mxman2k, Aug 23, 2016
    Last edited: May 3, 2017
    (OP)
    Many thanks everyone, i'm learning a few new commands as i go now :)

    I had a play with the script in a VM, i used the username as the account i created, for a test, i forgot i removed the %username% check , ran it manually and loads of text came up about file in use or something at a fair rate of knots lol.

    Good job it was a VM because through my silly mistake i really screwed up the account, the startmenu/search/clock or any apps didnt work.

    That will teach me check and recheck.

    2nd try of the revised script worked a charm even when pasted on the end of oobe.cmd so now it will check for that defaultuser0 and if present remove it from the fresh install automatically.

    I put REM's in to remind myself what the errorlevel numbers mean.

    As they say to learn is by trial and error, i learnt by my error lol.

    My revised script: Note: Must be run as Administrator!

    Code:
    REM Must be ran as Administrator to function correctly.
    SET UserToRemove="defaultuser0"
    REM 'CALL' check registry subroutine check for existance and remove.
    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
    REM -----------------------------------------------------------------------
    REM Results of ERRORLEVEL are:
    REM 0  -- If UserToRemove is found in the registry then run rest of script.
    REM 1  -- If UserToRemove is NOT found in the registry then exit script.
    REM -----------------------------------------------------------------------
    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 :Finish
    
    REM Remove that user...
    RMDIR "%SystemDrive%\Users\%ProfileName%" /s /q
    REG delete %1 /f >nul
    IF EXIST "%SystemDrive%\Users\%ProfileName%" GOTO :RetryDirRemove
    GOTO :Finish
    
    :RetryDirRemove
    TAKEOWN /F "%ProfileName%" >nul
    TIMEOUT /T 2 >nul
    ICACLS "%ProfileName%" /GRANT *S-1-1-0:F >nul
    TIMEOUT /T 2 >nul
    RMDIR "%SystemDrive%\Users\%ProfileName%" /s /q
    
    :Finish
    REM End of script...
    

    I will have a play with the WMIC line (in a VM). See what other mischief i can do lol.

    Once again thank you for your help. One day i 'might' be able to write this in assembler or other programming language, but for now batch is my new learning process like B.A.S.I.C was many years ago.

    Mx
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Compo

    Compo MDL Member

    Mar 29, 2011
    136
    106
    10
    #8 Compo, Aug 23, 2016
    Last edited by a moderator: Apr 20, 2017
    The following is a small command script that should identify if the required user exists:
    Code:
    @Echo Off
    SetLocal
    (SET UserToRemove=defaultuser0)
    (SET UserProfilePath=)
    (SET RegProfList=HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList)
    For /F "EOL=E Tokens=*" %%a In ('Reg Query "%RegProfList%" /f "S-1-5-21" /k'
    ) Do For /f "EOL=E Tokens=2*" %%b In (
    'Reg query "%%a" /v ProfileImagePath /f "%UserToRemove%" /d') Do (
    If /I "%%~nxc" Equ "%UserToRemove%" Set UserProfilePath=%%c)
    If Not Defined UserProfilePath Exit/B
    Echo(%%UserToRemove%%=%UserToRemove%
    Echo(%%UserProfilePath%%=%UserProfilePath%
    Pause
    If the user exists then it will output the two variables, otherwise it will exit!
     
  9. revertex

    revertex MDL Member

    May 30, 2010
    119
    46
    10
    #9 revertex, Aug 31, 2016
    Last edited by a moderator: Apr 20, 2017
    Ran in 2 different computers, ate all folders but desktop and appdata in current user profile without touch defaultuser0 account.
     
  10. revertex

    revertex MDL Member

    May 30, 2010
    119
    46
    10
    Ok, ran it a third time, this time as administrator, delete defaultuser as expected, plus current user profile folders.
     
  11. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    #11 mxman2k, Aug 31, 2016
    Last edited: Aug 31, 2016
    (OP)
    Both original and revised scripts need to be ran as administrator to allow permissions to remove the files and the registry editing. Have edited those posts.

    If the revised one is added to oobe.cmd or the batch file called from within oobe.cmd then it will be automatically ran as SYSTEM during the windows setup phase.

    It's a rough and ready approach but it does the job. :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    8,575
    15,645
    270
    Do you think is too much if I ask you to edit your first post and publish the final solution there? Please.
     
  13. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    #13 mxman2k, Aug 31, 2016
    Last edited: Aug 31, 2016
    (OP)
    @Mr.X sure i was going to do that once i have tidied it all up, have a extra bit to add about changing the 'Windows User' name in registry to installed username during oobe, just working out how to get REG Query to work and check if still in setup mode or setup completed then do that change.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  14. MIMMO61

    MIMMO61 MDL Senior Member

    Aug 19, 2009
    356
    106
    10
    #14 MIMMO61, Oct 29, 2016
    Last edited: Oct 29, 2016
    PERFECT, IT WORKS WELL.!
    I used it the first post script, the RunOnceEx procedure in ISO W10 (1607 b14393.351).
    I made the test virtual machine, and in the path "C: \ Users" is not present no folder "defaultuser0"

    Thank you
     
  15. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  16. LiLCruz

    LiLCruz MDL Novice

    Mar 24, 2012
    22
    3
    0
    #16 LiLCruz, Nov 6, 2016
    Last edited: Nov 6, 2016
    I might get some hate asking this how do I run it? Use notpad name it defaultuser0.bat I'm new using scripts.o_O I trying run it manually since already installed Windows.
     
  17. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    copy/paste the text into notepad , save as whatevername.CMD make sure it isn't whatevername.cmd.txt if it is just rename to .cmd.

    The .cmd bit is important as this tells windows that is is a command script and not a normal batch. Although if not using the script via oobe.cmd etc i don't think it really matters as .bat or .cmd type.

    Then once you have the cmd file, right click the file and run as administrator. If you just run the file by double clicking it will not have permissions to do its work.

    Hope this helps :D
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  18. NM156

    NM156 MDL Novice

    Jun 10, 2016
    18
    7
    0
    Hmn, not working for me any which way. I put it as a command file in my install wim @ Windows/Setup/Scripts and added it to run in the oobe.cmd. Honestly i'm just stumbling my way through it,
    but looks like this.
    oobe.cmd
    @echo off

    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    :: 'OOBE.cmd' -> 'Windows 10' • 'Windows 8.x' • 'Windows 7' • 'Windows Vista' : Oct 5|2015 ::
    :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    SET RQR=REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v "ProductName"&SET INL=IF NOT ERRORLEVEL 1

    IF EXIST "%windir%\Setup\scripts\Auto.cmd" CALL "%windir%\Setup\scripts\Auto.cmd"
    IF EXIST "%windir%\Setup\scripts\SetupComplete.cmd" CALL "%windir%\Setup\scripts\SetupComplete.cmd"
    IF EXIST "%windir%\Setup\scripts\DefaultUser0REM.cmd" CALL "%windir%\Setup\scripts\DefaultUser0REM.cmd"


    %RQR% | findstr /I "\<WINDOWS\>" | findstr /I "\<7\>" >nul&&%INL% GOTO :CLOSE
    %RQR% | findstr /I "\<WINDOWS\>" | findstr /I "\<VISTA\>" >nul&&%INL% GOTO :CLOSE

    ::Enables f8 key for Win 8.x and Win 10 in desktops and laptops | To disable this feature for tablets put :: in front of the line below
    bcdedit /set {default} bootmenupolicy legacy >nul

    :CLOSE
    DEL /F /Q %0% >nul

    I also tried it "in between" the lines of Auto.cmd and SetupComplete.cmd.
    I also tried just pasting it on to the end inside the oobe.cmd file like you mentioned.
    Any idea what i'm doing wrong?
     
  19. mxman2k

    mxman2k MDL Developer

    Jun 20, 2007
    5,679
    19,122
    180
    If the script is being run as an Administrator (manually ran) or via OOBE/SetupComplete then it should of worked.

    In the Multi-OEM/Retail Project i update, the same routine is used, however there is a few added tweaks, this may help get the script to work. It does in the MRP so here is a revised original version with the changes made within MRP. Mainly Timeouts to allow parts to complete.

    Code:
    REM ** Must be ran as Administrator to function correctly. **
    REM Simple script to check for defaultuser0 , correct Windows User name to account name, delete defaultuser0 files and clean up registry area.
    REM -
    REM  Designed for Windows 10 RS1/Anniversary Update.
    
    SET OobeState=0
    REG QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State" | findstr /I "\<IMAGE_STATE_COMPLETE\>" >nul && IF ERRORLEVEL=1 SET OobeState=1
    REM Returns - Oobestate 0 = not running via oobe.  1 = setup not complete ie within Windows setup's oobe stage.
    
    REM         add REM before, or delete the line below to allow RegisteredOwner rename via manual method if required.
    IF %OobeState%==0 GOTO :StartMain
    
    REM To change the RegisteredOwner registry entry to current username.
    REM It has to be deleted then re-added or fails tried /ve and other ways , only delete and remake works properly??
        IF EXIST "%SystemDrive%\Users\defaultuser0\" (
        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
        )
    
    :StartMain
    SET UserToRemove="defaultuser0"
    REM 'CALL' check registry subroutine check for existance and remove.
    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
    EXIT
    
    :ChkRegistry
    REM -----------------------------------------------------------------------
    REM Results of ERRORLEVEL are:
    REM 0  -- If UserToRemove is found in the registry then run rest of script.
    REM 1  -- If UserToRemove is NOT found in the registry then exit script.
    REM -----------------------------------------------------------------------
    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 :EOF
    
    REM Remove that user folder...
    RMDIR "%SystemDrive%\Users\defaultuser0" /s /q >NUL 2>&1
    
    REM Now remove user from profile list.
    REG delete %1 /f >nul 2>&1
    TIMEOUT /T 1 /NOBREAK >nul
    IF EXIST "%SystemDrive%\Users\defaultuser0" GOTO :RetryDirRemove
    GOTO :EOF
    
    :RetryDirRemove
    REM Attempt to force remove the folder.
    TAKEOWN /F "%SystemDrive%\Users\defaultuser0" >NUL 2>&1
    TIMEOUT /T 1 /NOBREAK >nul
    ICACLS "%SystemDrive%\Users\defaultuser0" /GRANT *S-1-1-0:F >NUL 2>&1
    TIMEOUT /T 1 /NOBREAK >nul
    RMDIR "%SystemDrive%\Users\defaultuser0" /s /q >NUL 2>&1
    TIMEOUT /T 1 /NOBREAK >nul
    
    :Finish
    REM End of script...
    

    Hope this helps, you can do a comparison between the original on this thread and the above code to see the changes. I does work in the MRP and has been since last October (2016) when i took over the project and added it in.

    The timeout delays was added for MRP because it would sometimes fail, so adding those extra 1 sec delays allows the commands time to complete.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  20. NM156

    NM156 MDL Novice

    Jun 10, 2016
    18
    7
    0
    Cool thanks. I was thinking that about that idea of timeouts in fact with something else i was having an issue with. Will give it a study and try. Appreciate it.