Click here to Skip to main content
15,885,546 members
Articles / Batch

Batch file caveat when running as administrator

Rate me:
Please Sign up or sign in to vote.
4.00/5 (1 vote)
1 Mar 2011CPOL2 min read 21.1K   2  
Are you sure your batch file will actually do what you intended?

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
1 Mar 2011Reto70
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...
Please Sign up or sign in to vote.
1 Mar 2011Br.Bill
First command of the file should be:PUSHD directory_you_want_to_be_inThat solves it always. No testing for anything. No need to error out, because your expected file's gonna be in the expected directory.

License

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


Written By
Engineer
Japan Japan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions