Solved

batch file not working with run as administrator

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
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…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

828 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