Batch files - the lost manual

Things you always forget how to do in Windows batch files when you really really need them:

Change to the directory where the batch file is located

%0\ >NUL 2>&1
cd %0\.. >NUL 2>&1
cd /d %0\.. >NUL 2>&1

Check a registry entry

REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\TrendMicro\PC-cillinNTCorp\CurrentVersion /V Server > %TEMP%\trend.txt
FIND /i "newserver" %TEMP%\trend.txt > nul
If errorlevel 0 If Not errorlevel 1 goto raAlreadyMoved
echo Please wait. Moving to new server...
call servermove.bat
goto raTrendDone
echo Already attached to new Trend Server ... skipping.
del %TEMP%\trend.txt

Read the contents of a file into a variable

for /F %%G in (certname.txt) do set CERTNAME=%%G
echo Certificate = %CERTNAME%.p12