I'm setting up a bat file to unattendedly remove local user profiles, but for some reason it keeps closing, skipping the pause command.
My .bat is as follows:
@ECHO OFF & CLS & ECHO.
REM Control admin rights.
REM NET FILE 1>NUL 2>NUL & IF ERRORLEVEL 1 (ECHO Dit bestand moet met administrator-rechten worden utgevoerd.
REM ECHO Druk op een toets om dit venster te sluiten. & ECHO. & PAUSE >NUL & EXIT /D)
REM After confirmation of admin rights.
CALL DelProf2.exe /L
PAUSE
REM Reboot when finished.
ECHO SHUTDOWN /R /T 0
PAUSE
I'm aware this isn't quite unattended yet (in case you're curious about the DelProf2.exe, see here) but that's because it's still in testing.
I'm confirming that the user is running my script with admin rights, then I'd like to list the user profiles (using the L switch fom delprof) and then I'd like to simulate a reboot command using ECHO. My window should ask for confirmation twice, given the 2 pause statements in the .bat.
Yet when I run the bat as administrator, the screen only flashes quickly, and disappears. What am I missing here?
Pause
does not ask for confirmation but rather any kind of keyboard input. How do you run this batch?cmd
as an administrator and run the batch from there? That way you would catch any error message you might miss if it's closing right after starting it.