troubleshooting Question

Windows 7 Batch file problem - directory changes when envoking admin rights

Avatar of jbobst
jbobst asked on
Windows BatchWindows 7
4 Comments1 Solution669 ViewsLast Modified:
I have a simple batch file that copies three files to my \%windir%\syswow64 directory and then does a regsvr32 on these three files.  The problem is, when I just run the batch file normally, it gives me an access denied error as Windows doesn't allow non-elevated copy commands to the syswow64 directory.  So then, you would think that you could just right click on the batch file and say "run as administrator".  The problem then is that when you run a batch file with elevated admin rights, it changes the current directory path for some reason and it can no longer find the files I am trying to copy!  How do I fix this?  Is there a way to reset the current directory in my batch file before it gets to the copy lines?

So just to clarify, I have a folder on the root (it could be anywhere) of my c:\ drive.  In this folder is the batch file and the three files I want to copy.  When I run the batch file as administrator, it changes the directory in the command prompt to c:\windows\system32 and it obviously cannot find the three files it needs to copy since they are not in the system32 folder to begin with.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros