You are not logged in.
To prevent a script from immediately exiting when started from Explorer (double-clicked), add this line to the end of your scripts;
wmic process where "name='cmd.exe' or name='tcc.exe'" get commandline | find "%~dpnx0" > nul && (
(echo.& set /P var=Press a key to exit...))
If you need to pass the correct return code (errorlevel) to a calling command, add this section to the end of your script;
:End
set exitCode=%errorlevel%
wmic process where "name='cmd.exe' or name='tcc.exe'" get commandline | find "%~dpnx0" > nul && (
(echo.& set /P var=Press a key to exit...))
exit /B %exitCode%
Let me know if it works for you!
tcc.exe: http://www.jpsoft.com/tccledes.htm
Offline
Interesting method, but I think you've over-engineered it.
(if /i "%cmdcmdline:"=%" NEQ "%comspec% " pause) & (exit /b %errorlevel%)
This method works on (at least) XP, 2000, 2003, 2008.
Last edited by bluesxman (11 Feb 2010 13:09)
cmd | *sh | ruby | chef
Offline
Yes your right, but only this much is required;
> if /i "%cmdcmdline:"=%" NEQ "%comspec% " pause
In my method, executing wmic.exe was potentially changing the errorlevel just before the script exited, so i had to save it as an envar and return it using exit /b <exitcode>.
Your 'exit /b %errorlevel%' is redundant i believe, but whatever. Good one.
Offline
Your 'exit /b %errorlevel%' is redundant i believe
Good point. I must confess that if I'm passing errorlevels out of a script it's typically one I've set myself, so I tend to forget that the last still stands!
cmd | *sh | ruby | chef
Offline