How do I run a batch file on a local network as Administrator? (Vista)

18,445

Solution 1

Network drive mappings exist per-user session, so when your shortcut runs within the security context of administrator, no drive mappings exist.

Try calling the batch script in your shortcut via UNC, rather than referencing a drive letter.

Solution 2

Cooper on serverfault answered my question:

Network drive mappings are saved per-session, so when your shortcut runs within the security context of administrator, no drive mappings exist (unless the administrator has a current session, via another runas, or via a current remote desktop session).

Try calling the batch script in your shortcut via UNC, rather than referencing a drive letter.

Solution 3

I'm guessing the drives are mapped? Shortcuts don't save credentials within themselves, that's not within their capabilities. If your network is on a domain, then you can make the shortcut use the runas /noprofile /user:Administrator {Shortcut} This will prompt you for your password everytime, but will insure that it runs as administrator.

The other option is to use psexec \{computer} -s -c {batch file} which will copy the batch file to the remote computer, and execute it as the system account. You have to have administrative privelages on the remote machine to use psexec, or you can specify a user/pass that does.

More information: runas: http://technet.microsoft.com/en-us/library/bb490994.aspx psexec: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx

Share:
18,445

Related videos on Youtube

Dan Gradl
Author by

Dan Gradl

I am a Software Developer at Conversica Inc. My primary work is writing code, however I sometimes have the opportunity to work with our infrastructure team on the deployment process. I enjoy thinking about problems from more than just a pure code perspective.

Updated on September 17, 2022

Comments

  • Dan Gradl
    Dan Gradl over 1 year

    I have a couple of batch files which must be run as Administrator. I can do so if they are on my machine, but when I put them on the network and then try to run them as Administrator, the command prompt simply shows no output and finishes, apparently without executing any of the code. When I run the network batch files normally, I at least get a bunch of error messages telling me that access is denied.

    Any ideas how to fix this behavior?

    I am executing these batch files via shortcut, and the shortcuts do not use UNC paths. I have also configured the shortcut to run as Administrator.

    • Jeff Miles
      Jeff Miles almost 15 years
      If the shortcuts don't use UNC paths, how are they referencing the batch files?
    • Dan Gradl
      Dan Gradl almost 15 years
      I have the drives mapped.
  • eatyourpeas
    eatyourpeas almost 15 years
    Indeed, a UNC path is invalid as the current working directory for cmd. You may not rely on things in the working dir (as that will default to somewhere else) or need to map network drives.
  • eatyourpeas
    eatyourpeas almost 15 years
    I am executing these batch files via shortcut, and the shortcuts do not use UNC paths. I have also configured the shortcut to run as Administrator. I don't have the correct permissions to use the two "runas" commands you suggested. If I can't find a solution, I will contact my admin.
  • Michael Clerx
    Michael Clerx over 9 years
    Is there a way of doing this is you only know a relative path?