none
Running .bat files as administrator on win 7 and win 2k8 machines

    Domanda

  • I have .bat which will be copied onto Win 7 and Win 2k8 machines remotely. The batch file contains scripts to stop and restart Windows services, like,

    net stop "Adobe Acrobat Update Service".

    Now when I run this batch file, I get "System error 5 has occurred. Access is denied."

    I understand that I need to run this batch file as administrator (here by administrator I mean, Windows default administrator.).

    Does anyone have a solution for this?

    P.S: 1) "run as" command inside the .bat file won't work, since you need to run the .bat file itself as administrator (here by administrator I mean, Windows default administrator.).

    2) I can create another batch file (say b.bat) containing the "run as" command and invoking the the original batch file (say a.bat), which has the command net stop "Adobe Acrobat Update Service". But still, this won't solve the issue, since you can run as, the user, who has administrator privileges and not run as administrator (here by administrator I mean, Windows default administrator.) itself.

    domenica 2 ottobre 2011 09:46

Risposte

  • Suhas,

    Can you explain me why you want to do this?
    Maby there are there some beter ways to achive your goal.

    The reason why this doesn't work is UAC who strips the administrator tokens from your user account.
    So it is not nesseary to use the default windows administrator account. Just a user with administrative priviliges will do you only need to run this command elevated.

    There are several ways to run this command elevated:

    1. Just right click on the batch file and choose the option run as administator.
      Quite simple but a no go if you wanna have a fully automated solution
    2. Use PsExec.exe  from the pstools suite (avaible here)
      If you use the command like this:
      PSEXEC -u domain\user -p password -h net stop spooler
      PSEXEC -u domain\user -p password -h net start spooler

      Or from a remote machine (pcX = remote management machine, pcY = machine where you want to restart the service.)
      Execute this command on machine pcX:
      PSEXEC \\pcY -u domain\user -p password -h net stop spooler
      PSEXEC \\pcY -u domain\user -p password -h net start spooler
    3. Create a sheduled task with the "highest privlilges" that executes your batch file.
    4. etc ...

    Kind Regards
    DFT


    IM me - TWiTTer: @DFTER
    martedì 4 ottobre 2011 13:54

Tutte le risposte

  • Suhas,

    Can you explain me why you want to do this?
    Maby there are there some beter ways to achive your goal.

    The reason why this doesn't work is UAC who strips the administrator tokens from your user account.
    So it is not nesseary to use the default windows administrator account. Just a user with administrative priviliges will do you only need to run this command elevated.

    There are several ways to run this command elevated:

    1. Just right click on the batch file and choose the option run as administator.
      Quite simple but a no go if you wanna have a fully automated solution
    2. Use PsExec.exe  from the pstools suite (avaible here)
      If you use the command like this:
      PSEXEC -u domain\user -p password -h net stop spooler
      PSEXEC -u domain\user -p password -h net start spooler

      Or from a remote machine (pcX = remote management machine, pcY = machine where you want to restart the service.)
      Execute this command on machine pcX:
      PSEXEC \\pcY -u domain\user -p password -h net stop spooler
      PSEXEC \\pcY -u domain\user -p password -h net start spooler
    3. Create a sheduled task with the "highest privlilges" that executes your batch file.
    4. etc ...

    Kind Regards
    DFT


    IM me - TWiTTer: @DFTER
    martedì 4 ottobre 2011 13:54
  • I Found the solution:

    http://www.youtube.com/watch?v=OGHQzg69vsg

    martedì 20 marzo 2012 09:10
  • Use the free tool (ELEVATE)  to run it as administrator

    http://www.winability.com/elevate/

    • Proposto come risposta jimbonano venerdì 30 marzo 2012 12:46
    venerdì 30 marzo 2012 12:46