Solved

batch file not working with run as administrator

Posted on 2010-09-14
4
1,320 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 34

Assisted Solution

by:Seth Simmons
Seth Simmons earned 500 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 34

Accepted Solution

by:
Seth Simmons earned 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

785 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