As you have already heard there is no need to elevate the script; so that part can be removed. I have no information about your Format.exe executable so cannot say for sure if that line is okay but would suggest you try running it without call. When checking if a directory exists, make sure you include a trailing back slash. There is no need to call :RunOnceEx, the increment can be done directly in that for loop. This would be your file after those changes: Code: @echo off setlocal EnableExtensions setlocal EnableDelayedExpansion "%WINDIR%\Setup\Files\Format.exe" set /a KEYNUM=1 SET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx REG ADD %KEY% /V TITLE /D "Windows Programlarinizi Yukluyor..." /f FOR %%i IN (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST "%%i:\Software\" (for /f "delims=" %%z in ('dir /b %%i:\Software\*.exe') do ( set /a KEYNUM+=1 REG ADD %KEY%\!KEYNUM! /VE /D "%%~nz" /f REG ADD %KEY%\!KEYNUM! /V 1 /D "%%i:\Software\%%z" )) RMDIR /S /Q "%~dp0" exit There are other changes you can make to the above script but none of them should affect it's ability to do what you need it to do. Tip Other than the Format.exe and RMDIR lines every other line can be run in your live system, you only need to check your registry to find out if your for loop works before deleting those entries.
Fail with Windows 10 1809. For me all commands that needs admin right (well all of them) won’t run. Access denied, I guess, since this is the error I get when I manually run after logon my setupcomplete.cmd with no admin right. My setupcomplete is ran as intended: Code: 2019-01-05 17:38:28, Info [windeploy.exe] RunUserProvidedScript: Found script at [C:\Windows\Setup\Scripts\SetupComplete.cmd]; executing with UI hidden... 2019-01-05 17:38:28, Info [windeploy.exe] RunUserProvidedScript: Successfully executed script; (returned with exit code 0x1) 2019-01-05 17:38:28, Info [windeploy.exe] Flushing registry to disk... 2019-01-05 17:38:28, Info [windeploy.exe] Flush took 16 ms. 2019-01-05 17:38:28, Info [windeploy.exe] Windeploy: Executing move/cleanup commands 2019-01-05 17:38:28, Info [windeploy.exe] WinDeploy.exe exiting with code [0x0] But even a simple command like below will fail because no script can write a file in system drive [c:] without admin right. Code: set log="%systemdrive%\custom.log" :: ------------------------------ echo. > %log% echo Setup complete OK >> %log% According to the documentation: I copy my SetupComplete.cmd in "sources\$OEM$\$$\Setup\scripts" and use NTlite for the rest. Edit: see my other post below to see the fix
Problem solved. The issue comes from NTLite if you copy $OEM$ BEFORE NTLite processes the image. The solution is to use NTLite to customize your image until process is complete but BEFORE creating ISO. This is the moment when you must copy $OEM$ to your Windows source folder. After that use NTLite to create your ISO and test it in a virtual machine. Always add logging output in your setupcomplete.cmd to easily control what have been done with success or error once the setup completed. Here is the Bug Report to NTLite forum.