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

GIMP Corporate Windows install script

This is a short script useful to install GIMP and all its dependencies without further user intervention:

' This installs The GIMP and all dependencies (eg. GTK+)
Option Explicit

Const windowStyle = 8  ' Display as active app

Dim result, oShell

If result = VBNo Then "gtk+-2.10.6-1-setup.exe /SP- /SILENT", windowStyle, True "gimp-2.2.13-i586-setup-1.exe /SP- /SILENT", windowStyle, True
ElseIf (result = VBYes) Then "gtk+-2.10.6-1-setup.exe /SP- /SILENT", windowStyle, True "gimp-2.2.13-i586-setup-1.exe /SP- /SILENT", windowStyle, True


Thanks for coolmohitz for this idea. Copying this into your /usr/bin directory enables easy proxy authentication for yum without storing your Windows username and password anywhere in .bashrc:


    if [ "$PROXY" == "" ]
    echo "PROXY environment variable not set. Set it now?"
    read -e -p "proxy address and port: http://" PROXY

    read -e -p "proxy username: " username
    read -es -p "proxy password: " password
    export http_proxy="http://$username:$password@$PROXY"
    export ftp_proxy="http://$username:$password@$PROXY"

    echo ""
    while [ "$yumcmd" != "exit" ]
    echo "Type yum commands now ('exit' to terminate):"
    read -e -p "(yum) " yumcmd
    if [ "$yumcmd" != "exit" ]
    yum $yumcmd
Syndicate content