Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

batch file not working with run as administrator

Posted on 2010-09-14
4
Medium Priority
?
1,332 Views
Last Modified: 2012-05-10
S: is a shared drive that contains a batch file   s:\myfolder\mylogin.bat
The batch file needs administrative rights because it has commands that copy files to the c:\program files\directory.

It worked under windows XP, but does not work under Windows 7 pro 64 bit.

If I run it as administrator, it fails when trying to access the S: drive.
If I run it as a normal user, it fails when trying to access the protected C: drive folders.

How do I get it to run with all all rights?


I suspected that Run As Administrator  is using the Local Administrator user profile, which does not have access to the network drive, so I run cmd as administrator.  Sure enough, the dos command line cannot ever do a dir s:
0
Comment
Question by:rberke
  • 2
  • 2
4 Comments
 
LVL 36

Assisted Solution

by:Seth Simmons
Seth Simmons earned 2000 total points
ID: 33678470
Use a second batch file for Windows 7 and add this line at the beginning:

net use s: \\server\share /persistent:no

When you run as administrator, no drives are mapped.
0
 
LVL 36

Accepted Solution

by:
Seth Simmons earned 2000 total points
ID: 33678488
0
 
LVL 5

Author Comment

by:rberke
ID: 33683958
I solved my problem without using your tip.

Here is a little more detail of my problem.  The annoyance was in myLogin.bat  in \\server\sharedfolder\. All my users run it automatically as part of the sbs daily login script.

On windows 7 machines, the script did not work. A step that copied data from the Server\Sharedfolder to c:\program filehave would fail with access denied to the c: drive.  

I turned of UAC and the problem went away.  

Of course, that solution is dangerous so I turned it back on and come up with a better solution.

I .  I created a shortcut to mylogin.bat in \\server\sharedfolder
2.  I set the mylogin.lnk shortcut property to say Run As Administrator
3.  I changed my sbs login to call myLogin.lnk  instead of myLogin.bat

I am not quite sure I understand why that worked, but it does.

I then discovered that users can also run mylogin.lnk  without any problems.  In other words, the shortcut link myLogin.bat does not lose S drive map whereas right clicking on mylogin.bat does.

This solved my problem.

Thanks for you suggestion anyhow, but  I am giving you points for your efforts.
0
 
LVL 5

Author Comment

by:rberke
ID: 33696910
Thanks even MORE.

I DID need to use your suggestion after all for a different reason.

I occasionally tell the users "Please do a daily reset".  Usually that just means for them to logoff and logon, but sometimes they have a bunch of stuff open.  So, to make things go faster, there is a shortcut on their desktop that lets them run the SBS Logon macro.  

This was working for XP users, but not for Windows 7 users.

To fix it, I created a file called S:\DontDeleteDailyResetInCDrive.bat with the following
   net use s: \\server\myShareName /persistent:no
   call "S:\SBSLogin.bat"

On windows 7 computers, I manually copied it from S: to c:\program files\MyCompanyPrograms\DontDeleteDailyResetInCDrive.bat
I then manually created a desktop shortcut call "Daily Reset.lnk" that has administrative rights.

I tried putting those last two steps into the logon script, but it did not seem to work, and I got tired of playing with it.







0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
While working, an annoying popup showing below will come and we cannot cancel or close it form the screen. The error message will come again and again.
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question