?
Solved

batch file not working with run as administrator

Posted on 2010-09-14
4
Medium Priority
?
1,331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

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 35

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

719 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