Running batch files as administrator change working directory

C

corradolab

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
 
B

Bob

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top