Solved

batch file not working with run as administrator

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

So many times I have seen the words written in a question "if only I could show you" or " I know how hard it is for you since you can't see it" in any zone. That has inspired me to write about this tool in windows 7 called "Problem Steps Recorder…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now