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 SiteMap

Tags: , , ,

Sponsored Links



Running batch files as administrator change working directory

Vista Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 07-01-2008
corradolab@ngi.it
 
Posts: n/a
Running batch files as administrator change working directory

Hi,

if you start a batch file from Explorer the working directory is the
directory which holds the file.
If you start a batch file from a shortcut you can specify a different
one.
But if you start a batch file as Administrator the working directory
is always C:\Windows\System32, even if the file is in a different
directory or is started from a shortcut whit an explict working
directory.

This cause every batch file calling another executable (batch, exe,
ecc.) to fail if not using absolute paths.
The quickest workaround is probably to edit the batch file changing
the current directory.
Something like:

CD \my_directory
CALL another_batch_file

My question is: why?
Is there a reason because the working directory is not respected or is
simply a missing functionality?

Kind regards,
Corrado
Reply With Quote
  #2  
Old 07-01-2008
 
Posts: n/a
Sorry, I don't know why, but if you insert cmd /c before the batch file
location I think it will solve the problem.

Maybe you can help me with a batch file. I Googled it but can't find an
answer.

I would like to know how I can create a batch file that will copy one file
to multiple drives.

I would also like to know how to do this with a file that is password
protected.
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
David H. Lipman
 
Posts: n/a
Re: Running batch files as administrator change working directory

TechArena.in is a leech of Usenet and fakes that it provides forums when they are
actually Usenet news groups and uses the vBulletin USENET gateway. In this case it is a
news group within the Microsoft.* hierarchy and can be directly accessed via the Microsoft
news server; MSNews.Microsoft.Com using a news client via TCP port 119.

Users of TechArena.in are strongly ENCOURAGED to drop the TechArena.in leech of
Usenet and access "this" News Group directly with the following News URL...

news://msnews.microsoft.com/microsof....vista.general

BTW: It is "The OP is not..." as the OP (original poster) is singular not plural :-)
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


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
How to change the order of files in directory mAHASWETA Operating Systems 5 09-01-2011 12:09 AM
Need help to working on Windows Server 2008 Files and Directory sharing Atalaya Networking & Security 5 29-11-2010 11:59 PM
Run as administrator not working for bat files inside folder having ( sraghunandan Vista Help 1 14-09-2010 05:27 PM
Can't change file association for DOS batch files Musawwir Spiegel Windows XP Support 10 11-03-2009 01:10 AM
Running Batch files with Task Scheduler brs90210 Window 2000 Help 7 09-05-2006 04:36 AM


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