Click here to Skip to main content
11,709,955 members (80,723 online)
Click here to Skip to main content

Batch file caveat when running as administrator

, 1 Mar 2011 CPOL 3.4K 2
Rate this:
Please Sign up or sign in to vote.
if you want to run the script in the folder where the script is store you can add the following code@ECHO %0 %*@pushd@cd /D "%~dp0"@cd....@pause@popdin most case %0 is the name of the script including the full path%~dp0 is only the drive and the path of the scriptcd...
if you want to run the script in the folder where the script is store you can add the following code

@ECHO %0 %*
@pushd
@cd /D "%~dp0"
@cd
....
@pause
@popd

in most case %0 is the name of the script including the full path
%~dp0 is only the drive and the path of the script
cd /D "%~dp0" changes the drive and the working path to the path of the script
HTH
Reto

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Reto70
Switzerland Switzerland
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralNice! Didn't know about %~dp0. 5. Pin
Indivara1-Mar-11 20:02
subeditorIndivara1-Mar-11 20:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150819.1 | Last Updated 1 Mar 2011
Article Copyright 2011 by Reto70
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid