Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Vista Newsgroups > Vista General

Vista - Running batch files as administrator change working directory

Reply
 
Old 01-07-2008   #1 (permalink)
corradolab


 
 

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

My System SpecsSystem Spec
Old 01-07-2008   #2 (permalink)
Bob


 
 

Re: Running batch files as administrator change working directory


<corradolab@xxxxxx> wrote in message
news:6626364e-e5de-40a1-adf4-495dd5399fe9@xxxxxx
Quote:

> 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
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.

Any ideas?








My System SpecsSystem Spec
Old 12-08-2008   #3 (permalink)
thesk8rjesus


 
 

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


--
thesk8rjesus
------------------------------------------------------------------------
thesk8rjesus's Profile: http://forums.techarena.in/members/thesk8rjesus.htm
View this thread: http://forums.techarena.in/vista-help/887281.htm

http://forums.techarena.in

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
How to determine a batch file is running as administrator General Discussion
Batch files, administrator, network drives Vista General
running batch files... Vista General
Running Batch Files in VISTA Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46