SetupComplete.cmd - applies in 1703, but not 1607

Discussion in 'Windows 10' started by MonarchX, Jun 29, 2017.

  1. MonarchX

    MonarchX MDL Expert

    May 5, 2007
    1,732
    313
    60
    I created a SetupComplete.cmd file that removes DefaultUser0 profile and it is placed in Windows\Setups\Scripts folder. With build 1703 this file automatically does what it was meant to do and removes DefaultUser0 profile. With build 1607 - it does not (and DefaultUser0 folder remains), but it works fine when launched manually. Why is that?

    I would also like to integrate KMS_VL_ALL as part of Post-Setup process, which requires placement the $OEM$ folder in Sources directory on the ISO, but it also uses SetupComplete.cmd. Is it possible to make both Post-Setup work as they should - SetupComplete.cmd in Windows\Setup\Scripts directory AND SetupComplete.cmd in $OEM$ folder inside the ISO?

    Note: SetupComplete.cmd in Scripts folder does not apply in build 1607 even when $OEM$ is not used / not placed in Sources folder on the ISO. However, I think both SetupComplete.cmd files apply in build 1703.

    This is the contents of the CMD file:
    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...
     
  2. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    47,232
    94,598
    450
    #2 Enthousiast, Jun 29, 2017
    Last edited: Jun 29, 2017
    It doesn't matter if it is in the $OEM$ folder or in the install.wim\windows\setup\scripts folder. The setupcomplete should simply work on all win 10 but the script is not always able to fix the problem, that's why some build in extra lines to complete it.
     
  3. MonarchX

    MonarchX MDL Expert

    May 5, 2007
    1,732
    313
    60
    Thank you for the information, but unfortunately, it does not help me one bit... I still don't know how to make it work for 1607 build and still don't know how to combine both of SetupComplete.cmd properly.
     
  4. syahendra

    syahendra MDL Novice

    Oct 26, 2013
    7
    3
    0
    Yes, it is true.
    I have read its readme.txt file

    There mention :

    Attempts to remove defaultuser0 and the correct UserID registry entry. (Windows 10 / Server 2016)

    Like the wishes of MonarchX
     
  5. Flipp3r

    Flipp3r MDL Expert

    Feb 11, 2009
    1,964
    907
    60
    Maybe your using an OEM key with 1607. If so it will skip setupcomplete.cmd.
    You can merge each batch or just rename them & use the call function:
    Code:
    Call remove_default0.cmd
    Call VL_Activate.cmd
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. MonarchX

    MonarchX MDL Expert

    May 5, 2007
    1,732
    313
    60
    That makes no sense...
     
  7. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    47,232
    94,598
    450
    What makes no sense. the fact MRP does the job you need to be done on all windows sku's imaginable, including Insider Previews?
     
  8. maestrosir

    maestrosir MDL Junior Member

    Aug 1, 2016
    65
    43
    0
    Sorry for my stupid question, but is it safe to remove the defaultuser0 user account?
     
  9. Enthousiast

    Enthousiast MDL Tester

    Oct 30, 2009
    47,232
    94,598
    450
    Yes, it shouldn't even have been there.