Go Back   TechArena Community > Technical Support > Computer Help > Windows Vista > Vista Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Running batch files as administrator change working directory

Vista Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-01-2008
Member
 
Join Date: Jan 2004
Posts: 38
Running batch files as administrator change working directory

I need a bit help with Batch files on the new Vista OS. I know if I start a batch file from Explorer the working directory is the directory which holds the file. And if I start a batch file from a shortcut then I can specify a different one, right? But here is the problem. When I start a batch file as Administrator the working directory is always C:\Windows\System32, even if the file is in a dissimilar directory or starts from a shortcut whit an explicit working directory. Due to this all my batch files get fails with all another executable (batch, exe, ecc.) in case not using absolute paths.

As far as I know the best method to edit the batch file is by changing the current directory. For example like this
CD \my_directory
CALL another_batch_file

Am I right up to here? If yes, then I would like to know if there is reason because the working directory is not respected or is simply a missing functionality. Any idea?

Reply With Quote
  #2  
Old 07-01-2008
Member
 
Join Date: Sep 2005
Posts: 61
Well i am not sure whether this will work for you but i think you should try out putting "cmd /c" before the batch file location. Just try out doing this and see if it fixes the issue.
Reply With Quote
  #3  
Old 08-12-2008
Member
 
Join Date: Dec 2008
Posts: 1
Re: Running batch files as administrator change working directory

Code:
@echo off
for %%F in (folder1 folder2 folder3) DO xcopy /h /r /k /x /y /S /E "\\servername\folder" "\\servername\%%F"
exit
This will look at the all the folder names 'folder1, folder2, and folder3' and will copy all files from the origin to them
Reply With Quote
  #4  
Old 29-12-2009
Member
 
Join Date: Dec 2009
Posts: 2
Re: Running batch files as administrator change working directory

In XP, %~dp0 should give you the path of the batch file. I don't have a box nearby to test Vista.

http://www.microsoft.com/resources/d....mspx?mfr=true
Reply With Quote
  #5  
Old 29-12-2009
Member
 
Join Date: Dec 2009
Posts: 2
Re: Running batch files as administrator change working directory

The OP are not the only people looking for the answers to this issue on the internets. Moron.
Reply With Quote
  #6  
Old 30-12-2009
Member
 
Join Date: Jan 2004
Posts: 38
Re: Running batch files as administrator change working directory

Thank you very much for all your helps guys. But still i have a bit problem, actually a small confusion. I request you to please tell me how exactly i can create the batch file that will copy one file to multiple drives. Also please let me know how to do this with a file that is password protected. Many thanks.
Reply With Quote
  #7  
Old 06-04-2011
Member
 
Join Date: Apr 2011
Posts: 1
Re: Running batch files as administrator change working directory

just put this as the first line:
chdir %~dp0

works in xp, vista, and win7
Reply With Quote
  #8  
Old 09-11-2011
Member
 
Join Date: Nov 2011
Posts: 2
Re: Running batch files as administrator change working directory

Quote:
Originally Posted by CapinWinky View Post
just put this as the first line:
chdir %~dp0

works in xp, vista, and win7
This unfortunately doesn't wok if the batch file was located on a different drive.
(e.g. on drive D: - chdir changes directory but not the drive letter)
Reply With Quote
  #9  
Old 09-11-2011
Member
 
Join Date: Nov 2011
Posts: 2
Re: Running batch files as administrator change working directory

you need to use
chdir /D %~dp0
to be sure that also the drive letter is correct
Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Vista > Vista Help
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Running batch files as administrator change working directory"
Thread Thread Starter Forum Replies Last Post
Need help to working on Windows Server 2008 Files and Directory sharing Atalaya Networking & Security 5 29-11-2010 10:59 PM
Delete the contents of a directory using Batch GUSSIE Operating Systems 3 11-09-2009 12:43 PM
Retrieving the current directory in batch Jacques25 Software Development 3 15-07-2009 11:36 PM
Can't change file association for DOS batch files pushpendra Windows XP Support 6 11-03-2009 12:10 AM


All times are GMT +5.5. The time now is 09:23 PM.