2

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.

2
  • If the shortcuts don't use UNC paths, how are they referencing the batch files?
    – Jeff Miles
    Jun 16, 2009 at 16:30
  • I have the drives mapped. Jun 16, 2009 at 16:37

6 Answers 6

3

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.

1
  • Is there a way of doing this is you only know a relative path? Aug 28, 2014 at 15:49
1

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

1

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.

0

I'm not entirely sure what you are asking.

However:

runas /user:mymachine\administrator cmd

Is usually the way you want to do that (if you are not already an admin.) You may also need to make sure you are specifying:

runas /user:mydomain\mydomainadmin cmd

as the local admin may not have permission to the resource you are trying to access.

It also occurred to me that your batch files may not be expecting UNC names like \\server\path\filename.txt, they may be expecting just drive:\path\filename.txt. You will need to make sure that they are not assuming that any path information will be in one particular format.

2
  • 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.
    – Johannes Rössel
    Jun 15, 2009 at 20:42
  • 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.
    – Paul Williams
    Jun 16, 2009 at 16:17
0

you could also try to create shortcuts of the batch files and then tick the "Run as administrator"option for the shortcuts (properties-advanced) and run them instead if it's possible. It works but I recommend using 'runas' instead...

0

As mentioned in the previous answer and the above comment, I had already placed this question on serverfault. Migrating it here as well has simply created a duplicate. If anyone who reads this has the ability to delete questions, please delete this one.

You must log in to answer this question.

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