Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
If the shortcuts don't use UNC paths, how are they referencing the batch files? –  Jeff Miles Jun 16 '09 at 16:30
    
I have the drives mapped. –  Paul Williams Jun 16 '09 at 16:37
add comment

6 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
Thanks, that was exactly what the problem was. –  Paul Williams Jun 16 '09 at 16:46
add comment

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|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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 '09 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 '09 at 16:17
add comment

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...

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.