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

  • I found that registry projects are hard but they do get the job done.

    bat files cannot invoke a higher privilege, it must be configured to do do from the first called bat file

     


    Windows MVP 2010-11, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint etc.

    My page on Video Card Problems is now my most popular landing page. My Page on SSD is now #2. See my gaming site for game reviews etc.

    Developer | Windows IT | Chess | Economics | Hardcore Games | Vegan Advocate | PC Reviews

    domenica 2 ottobre 2011 18:26
  • 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
  • if you rename BAT files to CMD you can use more functionality


    Windows MVP 2010-11, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint, Cloud, Virtualization etc. etc.

    Hardcore Games, Legendary is the only Way to Play

    Developer | Windows IT | Chess | Economics | Vegan Advocate | PC Reviews

    martedì 20 marzo 2012 23:41
  • 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