|
| |||||||||
| Tags: administrator, batch file, directory, windows vista |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
|
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. |
|
#3
| |||
| |||
| 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 |
|
#4
| |||
| |||
| 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 |
|
#5
| |||
| |||
| 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. |
|
#6
| |||
| |||
| 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 :-) |
|
#7
| |||
| |||
| Re: Running batch files as administrator change working directory
just put this as the first line: chdir %~dp0 works in xp, vista, and win7 |
|
#8
| |||
| |||
| Re: Running batch files as administrator change working directory Quote:
(e.g. on drive D: - chdir changes directory but not the drive letter) |
|
#9
| |||
| |||
| 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 |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |