0

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?

5
  • 1
    Pause does not ask for confirmation but rather any kind of keyboard input. How do you run this batch?
    – Seth
    Dec 15, 2016 at 10:39
  • I'm running the batch by right clicking the bat file and selecting 'run as administrator'. The DelProf2.exe is located in the same directory as the bat.
    – Yoeri
    Dec 15, 2016 at 10:41
  • 1
    Did you try to start a 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.
    – Seth
    Dec 15, 2016 at 10:42
  • Huh, seems I'm getting an error running the .exe now. I'll revisit that and check back.
    – Yoeri
    Dec 15, 2016 at 10:48
  • 1
    I've figured it out! It works fine if I run the .bat file locally. It doesn't work when running it from a network share, seems that's the issue here.. Windows doesn't recognise UNC paths, I'll try to rework that.
    – Yoeri
    Dec 15, 2016 at 10:54

1 Answer 1

0

The .bat file itself wasn't faulty in this case. It's that I'm trying to run it in a network share and windows dosen't support UNC paths. I'm going to try this solution.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .