@ECHO OFF&& SETLOCAL&& PUSHD "%~dp0"&& SETLOCAL ENABLEDELAYEDEXPANSION&& SETLOCAL ENABLEEXTENSIONS&& SET V=5&& IF NOT "!V!"=="5" (ECHO DelayedExpansion Failed&& GOTO :EOF) REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM Script Name: AskApache Batch Functions REM Description: Custom Windows Batch Functions coded like a Linux Shell Script. Windows XP, Win7, Win8 REM Author: AskApache REM Version: 9.7.5 REM Updated: 5/28/13 - 4:39pm REM Contributors: AskApache REM Author URI: https://www.askapache.com/ REM Donate URI: https://www.askapache.com/donate/ REM Copyright (C) 2013 AskApache.com REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ SCRIPT LOCAL VARIABLES ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ** administrator username, unless changed for more security, its Administrator SET ADMINUSER=admin REM ** runuser is the username you use when running this script SET RUNUSER=alienw REM ** DIRS FOR CRYPT SET _CROOT=C:\CRYPT SET _CBINS=%_CROOT%\BIN SET _CSCRIPTS=%_CROOT%\SCRIPTS REM ** Various vars for output used by functions SET _P1=^^^>^^^>^^^> SET _P2=++ SET _P3=:: SET _L1=+==============================================================================================================+ SET _L2=+--------------------------------------------------------------------------------------------------------------+ SET _T=%TIME: =0%&& SET _T=!_T::=-!&& SET _PLOG="%~dp0%~n0_!_T:~0,-2!log" REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ MAIN PROGRAM EXECUTION ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ :: Only allow certain users to run this script or die (prevents global STARTup or service running it) CALL :CHECKUSERVALID %RUNUSER% %ADMINUSER% :: Mount the truecrypt container CALL :CRYPTMOUNT "L" "%_CROOT%\LEONARDO" "%_CROOT%\LEONARDO_KEY" :: Start SOCKS TUNNEL CALL :RUNONE "L:\P\ENT2\MyEnTunnel\myentunnel.exe" "/NORMAL" :: Start Chrome CALL :RUNONE "C:\Users\alienw\AppData\Local\Google\Chrome\Application\chrome.exe" "/NORMAL" :: Start Mozilla Firefox CALL :RUNONE2 "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "/NORMAL" :: Start Adobe Dreamweaver CS6 CALL :RUNONE "C:\Program Files (x86)\Adobe\Adobe Dreamweaver CS6\Dreamweaver.exe" "/NORMAL" :: Start Thunderbird Portable CALL :RUNONE "L:\P\TB\ThunderbirdPortable\ThunderbirdPortable.exe" "/NORMAL" :: Start Adobe Photoshop CALL :RUNONE "C:\Program Files (x86)\Adobe\Adobe Photoshop CS6\Photoshop.exe" "/NORMAL" :: Start Skype CALL :RUNONE "L:\P\SKYPE\Phone\Skype.exe" "/NORMAL" REM ** EXIT Script ECHO. && ECHO. && title +++ %~f0 COMPLETED... EOF && ECHO EXITING SCRIPT... POPD && ENDLOCAL && GOTO :EOF REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ SCRIPT FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = CRYPTUNMOUNT - unmounts a truecrypt container and returns to CALLer. On fail, quit REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM CALL :CRYPTMOUNT "%LEONARDO%" "%LEONARDO_FILE%" "%LEONARDO_KEY%" REM CALL :CRYPTMOUNT "L" "%_CROOT%\LEONARDO" "%_CROOT%\LEONARDO_KEY" REM REM :: print the settings REM :: CALL :MP 3 "DRIVE: %DRIVE%"&&CALL :MP 3 " FILE: %FILE%"&&CALL :MP 3 " KEY: %KEY%"&&CALL :MP 3 " VOL: %VOL%" REM REM /a /auto REM /b /beep REM /c /cache REM /d /dismount REM /e /explore REM /f /force REM /h /history REM /k /keyfile REM /l /letter REM /m /mountoption REM /p /password REM /q /quit REM /s /silent REM /v /volume REM /w /wipecache REM REM ========================================================================================================================================================================= :CRYPTUNMOUNT SETLOCAL SET DRIVE=%~1 SET FILE=%~2 SET FILE2=%~2 SET KEY=%~3 SET KEY2=%~3 :: Check for Truecrypt or die CALL :EXISTORQUIT "%ProgramFiles%\TrueCrypt\TrueCrypt.exe" :: C:\CRYPT\DAVINCI -> \\?\Volume{ea0c4c60-da69-11df-920a-806d6172696f}\CRYPT\DAVINCI IF "%FILE:~1,1%" == ":" ( FOR /F %%i IN ('MOUNTVOL %FILE:~0,3% /L') DO @SET FILE2=%%i%FILE:~3% ) :: \\?\Volume{ea0c4c60-da69-11df-920a-806d6172696f}\CRYPT\DAVINCI -> C:\CRYPT\DAVINCI IF NOT "%KEY:~1,1%" == ":" ( ECHO > %TEMP%\cryptmount.log ( FOR %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @IF EXIST %%i:\ FOR /F %%b IN ('MOUNTVOL %%i:\ /L') DO @ECHO %%i %%b | FIND "%KEY:~0,49%" ) > %TEMP%\cryptmount.log FOR /F "tokens=1 delims= " %%i in (%TEMP%\cryptmount.log) DO @SET KEY2=%%i:\%KEY:~49% ) SET _TRUESTART=TrueCrypt.exe /c n /b /q background /h n /k "%KEY2%" /l %DRIVE% /d :: print banner CALL :MP 1 "Un-Mounting %FILE% to %DRIVE%:\ TrueCrypt" IF "D" == "C" ( :: print settings CALL :MP 3 "_TRUESTART: %_TRUESTART%" CALL :MP 3 "DRIVE: %DRIVE%" CALL :MP 3 " FILE: %FILE%" CALL :MP 3 " FILE2: %FILE2%" CALL :MP 3 " KEY: %KEY%" CALL :MP 3 " KEY2: %KEY2%" CALL :MP 3 "TRUE: %_TRUESTART%" ) :: checks the drive containing the truecrypt container file is present or dies MOUNTVOL %FILE2:~0,49% /L 2>NUL | FIND "\\?\Volume{" >NUL 2>&1 IF ERRORLEVEL 1 CALL :MDYE "%FILE2% NOT FOUND" :: checks the drive containing the truecrypt container keyfile is present or dies MOUNTVOL %KEY2:~0,3% /L 2>NUL | FIND "\\?\Volume{" >NUL 2>&1 IF ERRORLEVEL 1 CALL :MDYE "%KEY2% NOT FOUND" CALL :EXISTORQUIT "%FILE2%" CALL :EXISTORQUIT "%KEY2%" :: IF the drive is already mounted then continue, otherwise try to mount MOUNTVOL %DRIVE%:\ /L >NUL 2>&1 IF ERRORLEVEL 1 (CALL :MP 2 "%DRIVE% ALREADY UNMOUNTED" && EXIT /B) :: Un-Mount it START "Un-Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B %_TRUESTART% CALL :UNMOUNTWAIT "%DRIVE%:\" 60 :: try again in case of bad password and accidental keypress MOUNTVOL %DRIVE%:\ /L >NUL 2>&1 IF NOT ERRORLEVEL 1 (START "Un-Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B %_TRUESTART% && SLEEP 20) :: IF it still doesnt exist then quit MOUNTVOL %DRIVE%:\ /L >NUL 2>&1 IF NOT ERRORLEVEL 1 CALL :MDYE "Failed to un-mount %FILE% on %DRIVE%" CALL :MF && ENDLOCAL && EXIT /B REM ========================================================================================================================================================================= REM = CRYPTMOUNT - mounts a truecrypt container and returns to CALLer. On fail, quit REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM CALL :CRYPTMOUNT "%LEONARDO%" "%LEONARDO_FILE%" "%LEONARDO_KEY%" REM CALL :CRYPTMOUNT "L" "%_CROOT%\LEONARDO" "%_CROOT%\LEONARDO_KEY" REM REM :: print the settings REM :: CALL :MP 3 "DRIVE: %DRIVE%"&&CALL :MP 3 " FILE: %FILE%"&&CALL :MP 3 " KEY: %KEY%"&&CALL :MP 3 " VOL: %VOL%" REM REM /a /auto REM /b /beep REM /c /cache REM /d /dismount REM /e /explore REM /f /force REM /k /keyfile REM /l /letter REM /m /mountoption REM /p /password REM /q /quit REM /s /silent REM /v /volume REM /w /wipecache REM REM ========================================================================================================================================================================= :CRYPTMOUNT SETLOCAL SET DRIVE=%~1 SET FILE=%~2 SET FILE2=%~2 SET KEY=%~3 SET KEY2=%~3 :: Check for Truecrypt or die CALL :EXISTORQUIT "%ProgramFiles%\TrueCrypt\TrueCrypt.exe" :: C:\CRYPT\DAVINCI -> \\?\Volume{ea0c4c60-da69-11df-920a-806d6172696f}\CRYPT\DAVINCI IF "%FILE:~1,1%" == ":" ( FOR /F %%i IN ('MOUNTVOL %FILE:~0,3% /L') DO @SET FILE2=%%i%FILE:~3% ) :: \\?\Volume{ea0c4c60-da69-11df-920a-806d6172696f}\CRYPT\DAVINCI -> C:\CRYPT\DAVINCI IF NOT "%KEY:~1,1%" == ":" ( ECHO > %TEMP%\cryptmount.log ( FOR %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @IF EXIST %%i:\ FOR /F %%b IN ('MOUNTVOL %%i:\ /L') DO @ECHO %%i %%b | FIND "%KEY:~0,49%" ) > %TEMP%\cryptmount.log FOR /F "tokens=1 delims= " %%i in (%TEMP%\cryptmount.log) DO @SET KEY2=%%i:\%KEY:~49% ) SET _TRUESTART=TrueCrypt.exe /c n /b /q background /h n /k "%KEY2%" /l %DRIVE% /p /v "%FILE2%" :: print banner CALL :MP 1 "Mounting %FILE% to %DRIVE%:\ TrueCrypt" IF "D" == "C" ( :: print settings CALL :MP 3 "DRIVE: %DRIVE%" CALL :MP 3 " FILE: %FILE%" CALL :MP 3 " FILE2: %FILE2%" CALL :MP 3 " KEY: %KEY%" CALL :MP 3 " KEY2: %KEY2%" CALL :MP 3 "TRUE: %_TRUESTART%" ) :: checks the drive containing the truecrypt container file is present or dies MOUNTVOL %FILE2:~0,49% /L 2>NUL | FIND "\\?\Volume{" >NUL 2>&1 IF ERRORLEVEL 1 CALL :MDYE "%FILE2% NOT FOUND" :: checks the drive containing the truecrypt container keyfile is present or dies MOUNTVOL %KEY2:~0,3% /L 2>NUL | FIND "\\?\Volume{" >NUL 2>&1 IF ERRORLEVEL 1 CALL :MDYE "%KEY2% NOT FOUND" CALL :EXISTORQUIT "%FILE2%" CALL :EXISTORQUIT "%KEY2%" :: IF the drive is already mounted then continue, otherwise try to mount MOUNTVOL %DRIVE%:\ /L >NUL 2>&1 IF NOT ERRORLEVEL 1 (CALL :MP 2 "%DRIVE% ALREADY MOUNTED" && EXIT /B) :: Mount it START "Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B %_TRUESTART% CALL :MOUNTWAIT "%DRIVE%:\" 60 :: try again in case of bad password and accidental keypress MOUNTVOL %DRIVE%:\ /L >NUL 2>&1 IF ERRORLEVEL 1 (START "Mounting TrueCrypt" /D"%ProgramFiles%\TrueCrypt" /MIN /B %_TRUESTART% && SLEEP 20) :: IF it still doesnt exist then quit MOUNTVOL %DRIVE%:\ /L >NUL 2>&1 IF ERRORLEVEL 1 CALL :MDYE "Failed to mount %FILE% on %DRIVE%" CALL :MF && ENDLOCAL && EXIT /B REM ========================================================================================================================================================================= REM = MOUNTWAIT - wait for mounted drive REM ========================================================================================================================================================================= :MOUNTWAIT REM REM FOR %%i in (%*) DO (SET /A n+=1&& SET _!n!=%%i && ECHO !n! = %%i) SET /A N=%~2 SET /A N-=1 IF %n% LEQ 0 CALL :MP 2 "Timed out waiting to mount %~1" && EXIT /B SLEEP 2 MOUNTVOL %~1 /L >NUL 2>&1 IF ERRORLEVEL 1 CALL :MOUNTWAIT "%~1" %N% ELSE CALL :MP 2 "%~1 Mounted" EXIT /B REM ========================================================================================================================================================================= REM = UNMOUNTWAIT - wait for un-mounted drive REM ========================================================================================================================================================================= :UNMOUNTWAIT REM REM FOR %%i in (%*) DO (SET /A n+=1&& SET _!n!=%%i && ECHO !n! = %%i) SET /A N=%~2 SET /A N-=1 IF %n% LEQ 0 CALL :MP 2 "Timed out waiting to un-mount %~1" && EXIT /B SLEEP 2 MOUNTVOL %~1 /L >NUL 2>&1 IF NOT ERRORLEVEL 1 CALL :UNMOUNTWAIT "%~1" %N% ELSE CALL :MP 2 "%~1 Un-Mounted" EXIT /B REM ========================================================================================================================================================================= REM = CHECKUSERVALID - checks that defined username equals %ADMINUSER% or %RUNUSER%, then returns to CALLer REM ========================================================================================================================================================================= :CHECKUSERVALID :: EXIT IF USERNAME IS NOT DEFINED, CATCHES SYSTEM ACCOUNTS TRYING TO RUN WHEN IN GLOBAL STARTUP IF NOT DEFINED USERNAME EXIT SETLOCAL SET UP=no SET _PP1= %~1 SET _PP2= %~2 IF NOT "%_PP1%" == " " ( IF /I "%~1" == "%USERNAME%" SET UP=yes) IF NOT "%_PP2%" == " " ( IF /I "%~2" == "%USERNAME%" SET UP=yes) IF /I NOT "%UP%" == "yes" EXIT ENDLOCAL EXIT /B REM ======================================================================================= REM = REMOVEATJOB - runs job (START this file) every 5 minutes REM ======================================================================================= :REMOVEATJOB CALL :MP 1 "Removing AT JOB for %~n1" :: delete all AT jobs AT | FIND /I "%~1" AT | FOR /F "tokens=1" %%i IN ('FIND /I "%~1"') DO @AT %%i /delete /yes >NUL 2>&1 SET /A H=!TIME:~0,2!&& SET M=!TIME:~3,2! SET Y=%H%:%M%&& SET /A M+=5 IF !M! GEQ 60 ( SET /A H+=1&&SET /A M-=60 ) IF !H! GEQ 24 SET /A H-=24 SET M=0!M!&& SET H=0!H! :: create AT job REM ATLOG ECHO ATLOG: %TIME% = %Y%.......%Y% = %H:~-2%:%M:~-2% >> %_PLOG% REM AT %H:~-2%:%M:~-2% /INTERACTIVE %ComSpec% /E:ON /D /Q /C START /MIN %ComSpec% /E:ON /D /Q /C "%~f0" >NUL 2>&1 EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ EXECUTING FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = ADMINRUNONE - Runs %1 with admin rights IF neccessary REM ========================================================================================================================================================================= :ADMINRUNONE CALL :MP 3 "Exec %~1 as %ADMINUSER%" :: Check that file exists CALL :EXISTORQUIT "%~1" :: test for rights to the task scheduler :: %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C START /WAIT /MIN /B %SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C %~1 AT >NUL 2>&1 IF ERRORLEVEL 1 ( RUNAS /noprofile /user:%USERDOMAIN%\%ADMINUSER% "%~1" ) ELSE ( %COMSPEC% /E:ON /D /Q /T:0C /C "%~1" ) SLEEP 2 && CALL :MF && EXIT /B REM ========================================================================================================================================================================= REM = KILLRUNONE - Starts one instance of executable after verifying it exists and is not already running. REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM %~1 is location of executatable REM %~2 is optional (unless %~3 is used) START parameters REM %~3 is optional parameters for executable REM REM CALL :RUNONE "L:\P\LP\LightscreenPortable.exe" "/MAX" "/HIDE" REM ========================================================================================================================================================================= :KILLRUNONE SETLOCAL CALL :MP 1 "Killing %~n1" SETLOCAL SET P=%~1 ECHO %P%|FIND " " >NUL 2>&1 IF NOT ERRORLEVEL 1 ( SET P=%~nx1 ) PUSHD "%~dp1" :: SET _PP2 TO DEFAULT TO "/MIN" IF EMPTY SET _PP2=/MIN IF NOT "%~2" == "" SET _PP2=%~2 IF NOT "%~3" == "" SET _PP3=%~3 IF NOT "%~4" == "" SET _PP4=%~4 REM ECHO START %_P2% /D"%~dp1" %P% %_P3% %_P4%&& PAUSE&& :: CHECK FOR EXISTING PROCESSNAME ( %~n1 is file name without ext, %~nx1 is the file name and extension. ) tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %~nx1" 2>NUL | FIND "%~nx1 " >NUL 2>&1 IF ERRORLEVEL 1 (CALL :MP 2 "%~n1 already killed!" && SLEEP 1 ) ELSE (CALL :KILLBYNAME "%~nx1" ) POPD && ENDLOCAL && EXIT /B REM ========================================================================================================================================================================= REM = RUNONE - Starts one instance of executable after verifying it exists and is not already running. REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM %~1 is location of executatable REM %~2 is optional (unless %~3 is used) START parameters REM %~3 is optional parameters for executable REM REM CALL :RUNONE "L:\P\LP\LightscreenPortable.exe" "/MAX" "/HIDE" REM ========================================================================================================================================================================= :RUNONE SETLOCAL CALL :MP 1 "Starting %~n1" :: SLEEP FOR NICENESS, LOCAL VARS _P2 and _P3 SETLOCAL SET P=%~1 ECHO %P%|FIND " " >NUL 2>&1 IF NOT ERRORLEVEL 1 ( SET P=%~nx1 ) PUSHD "%~dp1" :: SET _PP2 TO DEFAULT TO "/MIN" IF EMPTY SET _PP2=/MIN IF NOT "%~2" == "" SET _PP2=%~2 IF NOT "%~3" == "" SET _PP3=%~3 IF NOT "%~4" == "" SET _PP4=%~4 :: CHECK THAT EXECUTABLE EXISTS CALL :EXISTORQUIT "%~1" REM ECHO START %_P2% /D"%~dp1" %P% %_P3% %_P4%&& PAUSE&& :: CHECK FOR EXISTING PROCESSNAME ( %~n1 is file name without ext, %~nx1 is the file name and extension. ) tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %~nx1" 2>NUL | FIND "%~nx1 " >NUL 2>&1 IF ERRORLEVEL 1 (START %_PP2% /D"%~dp1" %P% %_PP3% %_PP4%&& SLEEP 1 ) ELSE (CALL :MP 2 "%~n1 already running!" && SLEEP 1) POPD && ENDLOCAL && EXIT /B REM ========================================================================================================================================================================= REM = RUNONE2 - Starts one instance of executable after verifying it exists and is not already running. REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM %~1 is location of executatable REM %~2 is optional (unless %~3 is used) START parameters REM %~3 is optional parameters for executable REM REM CALL :RUNONE2 "L:\P\LP\LightscreenPortable.exe" "/MAX" "/HIDE" REM ========================================================================================================================================================================= :RUNONE2 SETLOCAL CALL :MP 1 "Starting %~n1" :: SLEEP FOR NICENESS, LOCAL VARS _P2 and _P3 SETLOCAL SET P=%~1 ECHO %P%|FIND " " >NUL 2>&1 IF NOT ERRORLEVEL 1 ( SET P=%~nx1 ) PUSHD "%~dp1" :: SET _PP2 TO DEFAULT TO "/MIN" IF EMPTY SET _PP2=/MIN IF NOT "%~2" == "" SET _PP2=%~2 IF NOT "%~3" == "" SET _PP3=%~3 IF NOT "%~4" == "" SET _PP4=%~4 :: CHECK THAT EXECUTABLE EXISTS CALL :EXISTORQUIT "%~1" REM ECHO START %_P2% /D"%~dp1" %P% %_P3% %_P4%&& PAUSE&& :: CHECK FOR EXISTING PROCESSNAME ( %~n1 is file name without ext, %~nx1 is the file name and extension. ) tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %~nx1" 2>NUL | FIND "%~nx1 " >NUL 2>&1 IF ERRORLEVEL 1 (%SYSTEMDRIVE%\WINDOWS\system32\cmd.exe /E:ON /D /Q /T:0C /C START %P% && SLEEP 1 ) ELSE (CALL :MP 2 "%~n1 already running!" && SLEEP 1) POPD && ENDLOCAL && EXIT /B REM ========================================================================================================================================================================= REM = RUNONEBG - Starts one instance of executable after verifying it exists and is not already running. REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM %~1 is location of executatable REM %~2 is optional (unless %~3 is used) START parameters REM %~3 is optional parameters for executable REM REM CALL :RUNONE "C:\Program Files\Synergy+\bin" "/min /wait" "-d ERROR -n m6300-fire -l c:\synergy.log -c C:\windows\synergy.sgc -a 10.66.66.2:24800" REM ========================================================================================================================================================================= :RUNONEBG SETLOCAL REM ECHO. && ECHO %_L1% && ECHO %~0 CALLED WITH: %* REM SET /A n=0 REM FOR %%i in (%*) DO (SET /A n+=1&& SET _!n!=%%i && ECHO !n! = %%i) REM ECHO %_L1% CALL :MP 1 "Starting %~n1" :: SLEEP FOR NICENESS, LOCAL VARS _P2 and _P3 SETLOCAL SET P=%~1 ECHO %P%|FIND " " >NUL 2>&1 IF NOT ERRORLEVEL 1 ( SET P=%~nx1 ) PUSHD "%~dp1" :: SET _P2 TO DEFAULT TO "/MIN" IF EMPTY SET OPTS=/min IF NOT "%~3" == "" SET OPTS=%~3 :: SET _P2 TO DEFAULT TO "/MIN" IF EMPTY SET STARTOPTS=/MIN IF NOT "%~2" == "" SET STARTOPTS=%~2 IF NOT "%~3" == "" SET OPTS=%~3 :: CHECK THAT EXECUTABLE EXISTS CALL :EXISTORQUIT "%~1" :: KILL ANY EXISTING PROCESSES CALL :KILLBYNAME "%~nx1" REM ECHO START %_P2% /D"%~dp1" %P% %_P3% %_P4%&& PAUSE&& :: CHECK FOR EXISTING PROCESSNAME ( %~n1 is file name without ext, %~nx1 is the file name and extension. ) tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %~nx1" 2>NUL | FIND /C "%~nx1 " 2>NUL | FIND "1" >NUL 2>&1 IF ERRORLEVEL 1 ( ECHO START %STARTOPTS% /D"%~dp1" %COMSPEC% /E:ON /F:ON /D /Q /T:0C /C %P% %OPTS% %SYSTEMROOT%\system32\runas.exe /noprofile /savecred /user:%RUNUSER% "cmd.exe /V:ON /D /Q /C \"start cmd.exe /E:ON /F:ON /D /Q /T:0C /K %~s1 %OPTS%^\"" SLEEP 3 tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %~nx1" 2>NUL | FIND "%~nx1 " >NUL 2>&1 IF NOT ERRORLEVEL 1 (CALL :MP 2 "%~nx1 now running!") ELSE (CALL :BEEP && CALL :MP 2 "%~nx1 still not running!") ) ELSE ( tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %~nx1" 2>NUL CALL :MP 2 "%~nx1 already running!" ) SLEEP 1 POPD && ENDLOCAL && EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ PROCESS/TASK FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = TASKS - REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM ========================================================================================================================================================================= :TASKS SETLOCAL SET _P=%~1 SET _PP= %~1 IF "%_PP%" == " " EXIT /B REM SORTABLES IF /I "%_P%" == "pid" ( tasklist.exe /V /NH | SORT /+29 && EXIT /B ) IF /I "%_P%" == "size" ( tasklist.exe /V /NH | SORT /+59 && EXIT /B ) IF /I "%_P%" == "user" ( tasklist.exe /V /NH | SORT /+89 && EXIT /B ) IF /I "%_P%" == "time" ( tasklist.exe /V /NH | SORT /+138 && EXIT /B ) IF /I "%_P%" == "window" ( tasklist.exe /V /NH | SORT /+152 && EXIT /B ) REM FILTERS IF /I "%_P%" == "image" ( tasklist.exe /V /NH /FI "IMAGENAME eq %~2" && EXIT /B ) IF /I "%_P%" == "username" ( tasklist.exe /V /NH /FI "USERNAME eq %~2" && EXIT /B ) IF /I "%_P%" == "running" ( tasklist.exe /V /NH /FI "STATUS eq Running" && EXIT /B ) IF /I "%_P%" == "status" ( tasklist.exe /V /NH /FI "STATUS eq %~2" && EXIT /B ) ENDLOCAL CALL :MF EXIT /B REM ======================================================================================= REM = KILLDUPES - kills duplicate processes, except for the one with lowest pid REM ======================================================================================= :KILLDUPES ECHO.&& CALL :SPEAK "KILLING DUPLICATE PUTTYS" REM Check that more than 1 process is running ::tasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2>nul | FIND /C "K Running" | FIND "1" >nul 2>&1 tasklist.exe /V /NH /FI "IMAGENAME eq %~1" 2>nul | FIND /C "K Running" | FIND "1" >nul 2>&1 IF NOT ERRORLEVEL 1 EXIT /B REM Create Filename in current dir (of this script) SET _T=%TIME: =0% SET _TT=%_T::=-% SET _TTT=%_TT:~0,8% SET _CMDS=%~dp0%_TTT%.log REM Create the file in the same dir as this script named for date and sorted by PID ::tasklist.exe /V /NH /FI "IMAGENAME eq %~1" /FI "USERNAME eq SYSTEM" 2>nul | SORT /+29 > "%_CMDS%" tasklist.exe /V /NH /FI "IMAGENAME eq %~1" 2>nul | SORT /+29 > "%_CMDS%" REM Check that the file was created or exit IF NOT EXIST "%_CMDS%" ( CALL :SPEAK "FILE CREATION FAILED" && EXIT /B ) REM kill all the processes found except for 1, do not kill the process with the lowest pid number FOR /F "usebackq tokens=2 skip=2" %%p IN (`type "%_CMDS%"`) DO taskkill.exe /F /PID %%p /T >nul 2>&1 REM erase the file ERASE /Q "%_CMDS%" >nul 2>&1 REM check that the file was erased IF EXIST "%_CMDS%" ( CALL :SPEAK "ERASE FILE FAILED" && EXIT /B ) ECHO OK EXIT /B REM ========================================================================================================================================================================= REM = KILLBYNAME - Kills all tasks with specific name REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %P%" /FI "STATUS eq running" /FI "USERNAME eq %COMPUTERNAME%\%RUNUSER%" | FIND /C "Running" | FIND "1" >NUL 2>&1 REM ========================================================================================================================================================================= :KILLBYNAME CALL :MP 1 "Killing all tasks with imagename: %~1" tasklist.exe /V /FO TABLE /FI "IMAGENAME eq %~nx1" 2>NUL | FIND /I "%~nx1 " >NUL 2>&1 IF NOT ERRORLEVEL 1 ( REM CALL :MP 1 "Found Tasks to Kill" REM tasklist.exe /V /FO TABLE /FI "IMAGENAME eq %~nx1" 2>NUL FOR /F "usebackq tokens=2" %%p IN (`tasklist.exe /V /FO TABLE /NH /FI "IMAGENAME eq %~nx1"`) DO taskkill.exe /F /PID %%p /T ) ELSE ( CALL :MP 1 "No tasks named %~nx1 to kill" ) EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ NETWORKING FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = PINGCHECK - PING address to make sure it is reachable REM ========================================================================================================================================================================= :PINGCHECK PING %~1 -n 1 -w 5000 | FIND "TTL=" >NUL 2>&1 IF ERRORLEVEL 1 ( PING google.com -n 1 -w 500 | FIND "TTL=" >NUL 2>&1 IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" && SLEEP 60 ) PING google.com -n 1 -w 5000 | FIND "TTL=" >NUL 2>&1 IF ERRORLEVEL 1 ( CALL :SPEAK "CHECK INTERNET CONNECTION" && SLEEP 60 ) PING google.com -n 1 -w 5000 | FIND "TTL=" >NUL 2>&1 IF ERRORLEVEL 1 ( CALL :SPEAK "KILL SOCKS PROGRAMS" SLEEP 100 ) ) EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ SCHEDULING FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = CREATEATJOB - runs job (START this file) every 5 minutes REM ========================================================================================================================================================================= :CREATEATJOB :: delete all putty AT jobs AT | FIND /C "%~f0" | FIND "1" >NUL 2>&1 IF ERRORLEVEL 1 ( AT|FOR /F "tokens=1" %%i IN ('FIND /I "%~f0"') DO AT %%i /delete /yes >NUL 2>&1 ) SET /A H=!TIME:~0,2!&& SET M=!TIME:~3,2! SET Y=%H%:%M%&& SET /A M+=5 IF !M! GEQ 61 ( SET /A H+=1&&SET /A M-=61 ) IF !H! GEQ 24 SET /A H-=24 SET M=0!M!&& SET H=0!H! :: create AT job AT %H:~-2%:%M:~-2% /INTERACTIVE %ComSpec% /E:ON /D /Q /C START /B /MIN %ComSpec% /E:ON /D /Q /C "%~f0" >NUL EXIT /B REM ========================================================================================================================================================================= REM = DELETEATJOBS - deletes jobs whose cmd contains this files name REM ========================================================================================================================================================================= :DELETEATJOBS AT | FIND /C "%~f0" | FIND "1" >NUL 2>&1 IF ERRORLEVEL 1 ( AT|FOR /F "tokens=1" %%i IN ('FIND /I "%~f0"') DO AT %%i /delete /yes >NUL 2>&1 ) EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ FILE OPERATION FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = EXAMINEFILE - FINDs useful strings in file, then returns to CALLer REM ========================================================================================================================================================================= :EXAMINEFILE CALL :MP 1 "Examine File %~1" CALL :EXISTORQUIT "%~1" STRINGS "%~1" | FINDSTR /R /C:"[A-Z][A-Z]\=" CALL :MF EXIT /B REM ========================================================================================================================================================================= REM = EXISTORQUIT - checks %~1 exists, IF it does returns to CALLer, otherwise, quit REM ========================================================================================================================================================================= :EXISTORQUIT :: CALL :MP 1 "Checking for %~1" IF NOT EXIST "%~1" CALL :MDYE "%~1 NOT FOUND" EXIT /B REM ========================================================================================================================================================================= REM = RR - IF file %1 EXISTs then :MT "Removing %1" then :MF, then ( or IF %1 not EXISTs) returns to CALLer REM ========================================================================================================================================================================= :RR CALL :MP 1 "Removing %~1" IF EXIST "%~1" ERASE /q "%~1" CALL :MF && EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ TASK/FUNCTION FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = ADMINSHELL - sets prompt, then returns to CALLer REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM = CALL :ADMINSHELL %ADMINUSER% REM = %SYSTEMROOT%\system32\runas.exe /profile /savecred /user:%ADMINUSER% "cmd.exe /V:ON /D /Q /C \"start \"[%ADMINUSER%@!COMPUTERNAME!]\" /D %_CBINS% cmd.exe /E:ON /F:ON /D /Q /T:0C /K prompt [%ADMINUSER%@%COMPUTERNAME%]$s$c$d$f$s[$p$m]$_$$$s"" REM ========================================================================================================================================================================= :ADMINSHELL SETLOCAL SET _CMDPROMPT=cmd.exe /E:ON /F:ON /D /Q /T:0C /K prompt [%ADMINUSER%@%COMPUTERNAME%]$s$c$d$f$s[$p$m]$_$$$s SET _CMDSTART=cmd.exe /V:ON /D /Q /C \"start \"[%ADMINUSER%@!COMPUTERNAME!]\" SET _RUNAS=%SYSTEMROOT%\system32\runas.exe /profile /savecred /user:%ADMINUSER% CALL :MP 1 "Creating Admin Shell" CALL :EXISTORQUIT "%SYSTEMROOT%\system32\runas.exe" IF NOT "%~1" == "" SET ADMINUSER=%~1 %_RUNAS% "%_CMDSTART% /D %_CBINS% %_CMDPROMPT%"" CALL :MF ENDLOCAL EXIT /B REM ========================================================================================================================================================================= REM = LOCKDOWN - locks workstation, then returns to CALLer (pointless) REM ========================================================================================================================================================================= :LOCKDOWN RUNDLL32 USER32.DLL,LockWorkStation && EXIT /B REM ========================================================================================================================================================================= REM = SHUTDOWNIN - initiates shutdown, then returns to CALLer (pointless) REM ========================================================================================================================================================================= REM shutdown /a aborts :SHUTDOWNIN SHUTDOWN -r -t "%~1" && EXIT /B REM ========================================================================================================================================================================= REM = CREATEHELP - creates a file in the cwd named help.txt of all ms-dos help commands, then returns to CALLer (pointless) REM ========================================================================================================================================================================= :CREATEHELP SET H=help.txt ECHO > %H% FOR /F "tokens=1 delims= " %i IN ('help') DO ECHO.>>%H%&&ECHO.>>%H%&&ECHO.>>%H%ECHO ----%i---------------- >>%H%&&ECHO =============%i===>>%H%&& help %i >>%H% EXIT /B REM ========================================================================================================================================================================= REM = LISTSERVICES - lists services, then returns to CALLer REM ========================================================================================================================================================================= :LISTSERVICES SC query state= all type= all | FOR /F "tokens=2" %%i IN ('FIND /I "SERVICE_NAME"') DO @ECHO %%i SC query | FOR /F "tokens=2" %%i IN ('FIND /I "SERVICE_NAME"') DO @ECHO %%i EXIT /B REM ========================================================================================================================================================================= REM = LISTDRIVELETTERS - Shows list of all currently mounted drive letters REM ========================================================================================================================================================================= :LISTDRIVELETTERS FOR %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @IF EXIST %%i:\ FOR /F %%b IN ('MOUNTVOL %%i:\ /L') DO @ECHO %%i:\ = %%b EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ CONSOLE FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = SETPROMPT - sets prompt, then returns to CALLer REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM = [user@MACHINE] [C:\DR\PEPPER\SCRIPTS] REM = > REG /? REM REM ========================================================================================================================================================================= :SETPROMPT set PROMPT=$_[%USERNAME%@%USERDOMAIN%]$S[$P]$_$M$G && EXIT /B REM ========================================================================================================================================================================= REM = MSETCOLOR - SET colors for screen, then returns to CALLer REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM 0 = Black 8 = Gray REM 1 = Blue 9 = Light Blue REM 2 = Green A = Light Green REM 3 = Aqua B = Light Aqua REM 4 = Red C = Light Red REM 5 = Purple D = Light Purple REM 6 = Yellow E = Light Yellow REM 7 = White F = Bright White REM REM ========================================================================================================================================================================= :MSETCOLOR COLOR %~1 && EXIT /B REM ========================================================================================================================================================================= REM = MSETCONSOLE - sets the cols and lines of current screen buffer, then returns to CALLer REM ========================================================================================================================================================================= :MSETCONSOLE MODE CON COLS=%~1 LINES=%~2 && EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ OUTPUT/DISPLAY FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = BEEP - beeps once, then returns to CALLer REM ========================================================================================================================================================================= :BEEP @ECHO  && EXIT /B REM ========================================================================================================================================================================= REM = SPEAK - Speak text REM ========================================================================================================================================================================= :SPEAK nircmd.exe speak text "%~1" 5 60 ECHO "%~1" EXIT /B REM ========================================================================================================================================================================= REM = MF - SLEEPs for 1 second, then prints out completed message, followed by 2 blank lines, then returns to CALLer REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM [COMPLETED] REM REM ========================================================================================================================================================================= :MF SLEEP 1 && ECHO [COMPLETED] && ECHO. && ECHO. && EXIT /B REM ========================================================================================================================================================================= REM = MM - prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1..., L2, blank line, then returns to CALLer REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM +==============================================================================================================+ REM >>> Title Changed To This... REM +--------------------------------------------------------------------------------------------------------------+ REM REM ========================================================================================================================================================================= :MM SLEEP 1 && ECHO. && ECHO %_L1% && title +++ %~1... && ECHO %_P1% %~1... && ECHO %_L2% && ECHO. && EXIT /B REM ========================================================================================================================================================================= REM = MT - prints blank line, L1, changes title of the interpreter window to %~1, prints >>> %~1..., L2, blank line, then returns to CALLer REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM +==============================================================================================================+ REM >>> Title Changed To This... REM +--------------------------------------------------------------------------------------------------------------+ REM REM ========================================================================================================================================================================= :MT CALL :MM "%~1" && CALL :SPEAK "%~1" && EXIT /B REM ========================================================================================================================================================================= REM = MP - , then returns to CALLer REM ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM REM P1=>>> REM P2=++ REM P3=:: REM REM ========================================================================================================================================================================= :MP IF "%~1" == "1" ECHO %_P1% %~2 && EXIT /B IF "%~1" == "2" ECHO %_P2% %~2 && ECHO. && EXIT /B IF "%~1" == "3" ECHO %_P3% %~2 && EXIT /B EXIT /B REM ========================================================================================================================================================================= REM = MP3 - ECHO %~1, speak %~1 with nircmd.exe, then returns to CALLer REM ========================================================================================================================================================================= :MP3 CALL :MP 1 "%~1" && CALL :SPEAK "%~1" && EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ SCRIPT EXIT FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = MDYE - exit script with message %~1, then returns to CALLer REM ========================================================================================================================================================================= :MDYE SETLOCAL SET _M= %~1 IF NOT "%_M%" == " " SET _M=REASON: %~1 ECHO. && ECHO. && title +++ %~f0 COMPLETED... %_M% CALL :MP 1 "EXITING SCRIPT... %_M%" && ECHO. && ECHO. && SLEEP 10 POPD && ENDLOCAL && PAUSE && EXIT /B && EXIT /B REM ========================================================================================================================================================================= REM = MKILL - exit cmd processor with message %~1 REM ========================================================================================================================================================================= :MKILL SETLOCAL SET _M= %~1 IF NOT "%_M%" == " " SET _M=REASON: %~1 ECHO. && ECHO. && CALL :MP 1 "EXITING CMD WINDOW IN 3 SECONDS... %_M%" && ECHO. && ECHO. && SLEEP 3 ENDLOCAL && EXIT && EXIT && EXIT REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ PARAMETER TESTING FUNCTIONS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ========================================================================================================================================================================= REM = PARAMTEST - tests params, then returns to CALLer REM ========================================================================================================================================================================= :PARAMTEST ECHO. && CALL :MP 1 "PARAMTEST CALLED WITH: %*" && ECHO %_L1% SET _P= %~1 IF NOT "%_P%" == " " ( ECHO %%1 = %1 && ECHO %%~f1 = %~f1 && ECHO %%~d1 = %~d1 && ECHO %%~p1 = %~p1 ECHO %%~n1 = %~n1 && ECHO %%~x1 = %~x1 && ECHO %%~s1 = %~s1 && ECHO %%~dp1 = %~dp1 ECHO %%~nx1 = %~nx1 && ECHO %%~$PATH:1 = %~$PATH:1 && ECHO %%~dp$PATH:1 = %~dp$PATH:1 && ECHO %_L1% ) SET _P= %~2 IF NOT "%_P%" == " " ( ECHO %%2 = %2 && ECHO %%~f2 = %~f2 && ECHO %%~d2 = %~d2 && ECHO %%~p2 = %~p2 ECHO %%~n2 = %~n2 && ECHO %%~x2 = %~x2 && ECHO %%~s2 = %~s2 && ECHO %%~dp2 = %~dp2 ECHO %%~nx2 = %~nx2 && ECHO %%~$PATH:2 = %~$PATH:2 && ECHO %%~dp$PATH:2 = %~dp$PATH:2 && ECHO %_L1% ) SET _P= %~3 IF NOT "%_P%" == " " ( ECHO %%3 = %3 && ECHO %%~f3 = %~f3 && ECHO %%~d3 = %~d3 && ECHO %%~p3 = %~p3 ECHO %%~n3 = %~n3 && ECHO %%~x3 = %~x3 && ECHO %%~s3 = %~s3 && ECHO %%~dp3 = %~dp3 ECHO %%~nx3 = %~nx3 && ECHO %%~$PATH:3 = %~$PATH:3 && ECHO %%~dp$PATH:3 = %~dp$PATH:3 && ECHO %_L1% ) SET _P= %~4 IF NOT "%_P%" == " " ( ECHO %%4 = %4 && ECHO %%~f4 = %~f4 && ECHO %%~d4 = %~d4 && ECHO %%~p4 = %~p4 ECHO %%~n4 = %~n4 && ECHO %%~x4 = %~x4 && ECHO %%~s4 = %~s4 && ECHO %%~dp4 = %~dp4 ECHO %%~nx4 = %~nx4 && ECHO %%~$PATH:4 = %~$PATH:4 && ECHO %%~dp$PATH:4 = %~dp$PATH:4 && ECHO %_L1% ) SET _P= %~5 IF NOT "%_P%" == " " ( ECHO %%5 = %5 && ECHO %%~f5 = %~f5 && ECHO %%~d5 = %~d5 && ECHO %%~p5 = %~p5 ECHO %%~n5 = %~n5 && ECHO %%~x5 = %~x5 && ECHO %%~s5 = %~s5 && ECHO %%~dp5 = %~dp5 ECHO %%~nx5 = %~nx5 && ECHO %%~$PATH:5 = %~$PATH:5 && ECHO %%~dp$PATH:5 = %~dp$PATH:5 && ECHO %_L1% ) SET _P= %~6 IF NOT "%_P%" == " " ( ECHO %%6 = %6 && ECHO %%~f6 = %~f6 && ECHO %%~d6 = %~d6 && ECHO %%~p6 = %~p6 ECHO %%~n6 = %~n6 && ECHO %%~x6 = %~x6 && ECHO %%~s6 = %~s6 && ECHO %%~dp6 = %~dp6 ECHO %%~nx6 = %~nx6 && ECHO %%~$PATH:6 = %~$PATH:6 && ECHO %%~dp$PATH:6 = %~dp$PATH:6 && ECHO %_L1% ) SET _P= %~7 IF NOT "%_P%" == " " ( ECHO %%7 = %7 && ECHO %%~f7 = %~f7 && ECHO %%~d7 = %~d7 && ECHO %%~p7 = %~p7 ECHO %%~n7 = %~n7 && ECHO %%~x7 = %~x7 && ECHO %%~s7 = %~s7 && ECHO %%~dp7 = %~dp7 ECHO %%~nx7 = %~nx7 && ECHO %%~$PATH:7 = %~$PATH:7 && ECHO %%~dp$PATH:7 = %~dp$PATH:7 && ECHO %_L1% ) SLEEP 3 CALL :MF EXIT /B REM ========================================================================================================================================================================= REM = PARAMTESTHELP - show params help, then returns to CALLer REM ========================================================================================================================================================================= :PARAMTESTHELP ECHO %%~1 Expands %%1 and removes any surrounding quotation marks ECHO %%~f1 Expands %%1 to a fully qualified path name. ECHO %%~d1 Expands %%1 to a drive letter. ECHO %%~p1 Expands %%1 to a path. ECHO %%~n1 Expands %%1 to a file name. ECHO %%~x1 Expands %%1 to a file extension. ECHO %%~s1 Expanded path contains short names only. ECHO %%~a1 Expands %%1 to file attributes. ECHO %%~t1 Expands %%1 to date and time of file. ECHO %%~z1 Expands %%1 to size of file. ECHO %%~dp1 Expands %%1 to a drive letter and path. ECHO %%~nx1 Expands %%1 to a file name and extension. ECHO %%~ftza1 Expands %%1 to a dir-like output line. ECHO %%~$PATH:1 Searches the dirs in PATH expanding %%1 to fully qualified name of first found. If var name isn't defined or the files not found, expands to empty string. ECHO %%~dp$PATH:1 Searches the directories listed in the PATH environment variable for %%1 and expands to the drive letter and path of the first one found. CALL :MF EXIT /B REM ========================================================================================================================================================================= REM = PARAMSHORT - REM ========================================================================================================================================================================= :PARAMSHORT IF NOT "%~1" == "" ECHO %_L2%&& ECHO %%1 = %1&& ECHO %%~f1 = %~f1&& ECHO %%~p1 = %~p1&& ECHO %%~n1 = %~n1&& ECHO %%~x1 = %~x1&& ECHO %%~s1 = %~s1&& ECHO %%~dp1 = %~dp1&& ECHO %%~nx1 = %~nx1 IF NOT "%~2" == "" ECHO %_L2%&& ECHO %%2 = %2&& ECHO %%~f2 = %~f2&& ECHO %%~p2 = %~p2&& ECHO %%~n2 = %~n2&& ECHO %%~x2 = %~x2&& ECHO %%~s2 = %~s2&& ECHO %%~dp2 = %~dp2&& ECHO %%~nx2 = %~nx2 IF NOT "%~3" == "" ECHO %_L2%&& ECHO %%3 = %3&& ECHO %%~f3 = %~f3&& ECHO %%~p3 = %~p3&& ECHO %%~n3 = %~n3&& ECHO %%~x3 = %~x3&& ECHO %%~s3 = %~s3&& ECHO %%~dp3 = %~dp3&& ECHO %%~nx3 = %~nx3 IF NOT "%~4" == "" ECHO %_L2%&& ECHO %%4 = %4&& ECHO %%~f4 = %~f4&& ECHO %%~p4 = %~p4&& ECHO %%~n4 = %~n4&& ECHO %%~x4 = %~x4&& ECHO %%~s4 = %~s4&& ECHO %%~dp4 = %~dp4&& ECHO %%~nx4 = %~nx4 IF NOT "%~5" == "" ECHO %_L2%&& ECHO %%5 = %5&& ECHO %%~f5 = %~f5&& ECHO %%~p5 = %~p5&& ECHO %%~n5 = %~n5&& ECHO %%~x5 = %~x5&& ECHO %%~s5 = %~s5&& ECHO %%~dp5 = %~dp5&& ECHO %%~nx5 = %~nx5 IF NOT "%~6" == "" ECHO %_L2%&& ECHO %%6 = %6&& ECHO %%~f6 = %~f6&& ECHO %%~p6 = %~p6&& ECHO %%~n6 = %~n6&& ECHO %%~x6 = %~x6&& ECHO %%~s6 = %~s6&& ECHO %%~dp6 = %~dp6&& ECHO %%~nx6 = %~nx6 IF NOT "%~7" == "" ECHO %_L2%&& ECHO %%7 = %7&& ECHO %%~f7 = %~f7&& ECHO %%~p7 = %~p7&& ECHO %%~n7 = %~n7&& ECHO %%~x7 = %~x7&& ECHO %%~s7 = %~s7&& ECHO %%~dp7 = %~dp7&& ECHO %%~nx7 = %~nx7 IF NOT "%~8" == "" ECHO %_L2%&& ECHO %%8 = %8&& ECHO %%~f8 = %~f8&& ECHO %%~p8 = %~p8&& ECHO %%~n8 = %~n8&& ECHO %%~x8 = %~x8&& ECHO %%~s8 = %~s8&& ECHO %%~dp8 = %~dp8&& ECHO %%~nx8 = %~nx8 EXIT /B REM ========================================================================================================================================================================= REM = SHOWPARAMS - REM ========================================================================================================================================================================= :SHOWPARAMS SETLOCAL >NUL 2>&1 ECHO RUNNING LABEL :SHOWPARAMS 1 ECHO %_L1% && ECHO %* && ECHO %_L2% SET n=0 FOR %%i in (%*) DO ( SET LL=%1&& SET /A n+=1&& ECHO !n! = %%i ) ECHO %_L2% ENDLOCAL >NUL 2>&1 EXIT /B REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ++ ++ REM ++ HELP AND SYNTAX FOR MISC COMMANDS ++ REM ++ ++ REM ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ REM ---- START ------------------------------------------------- REM START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED] [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL] [/WAIT] [/B] [cmd/program] [parameters] REM REM "title" Title to display in window title bar. REM path Starting directory REM B Start application without creating a new window. REM I The new environment will be the original environment passed to the cmd.exe and not the current environment. REM MIN Start window minimized REM MAX Start window maximized REM SEPARATE Start 16-bit Windows program in separate memory space REM SHARED Start 16-bit Windows program in shared memory space REM LOW Start application in the IDLE priority class REM NORMAL Start application in the NORMAL priority class REM HIGH Start application in the HIGH priority class REM REALTIME Start application in the REALTIME priority class REM ABOVENORMAL Start application in the ABOVENORMAL priority class REM BELOWNORMAL Start application in the BELOWNORMAL priority class REM WAIT Start application and wait for it to terminate REM cmd/program IF it is an internal cmd command or a batch file then the command processor is run with the /K switch to cmd.exe. Window REMains after command is run. REM parameters These are the parameters passed to the command/program REM ---- cmd ----------------------------------------------------------------- REM CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string] REM REM /C Carries out the command specified by string and then terminates REM /K Carries out the command specified by string but REMains REM /S Modifies the treatment of string after /C or /K (see below) REM /Q Turns ECHO off REM /D Disable execution of AutoRun commands from registry (see below) REM /A Causes the output of internal commands to a pipe or file to be ANSI REM /U Causes the output of internal commands to a pipe or file to be Unicode REM /T:fg Sets the foreground/background colors (see COLOR /? for more info) REM /E:ON Enable command extensions (see below) REM /E:OFF Disable command extensions (see below) REM /F:ON Enable file and directory name completion characters (see below) REM /F:OFF Disable file and directory name completion characters (see below) REM /V:ON Enable delayed environment variable expansion using ! as the delimiter. REM /V:OFF Disable delayed environment expansion. REM REM IF /D was NOT specified, then when CMD.EXE STARTs, it looks for the following registry variables, and executes them first. REM HKLM\Software\Microsoft\Command Processor\AutoRun and/or HKCU\Software\Microsoft\Command Processor\AutoRun REM ---- TrueCrypt ------------------------------------------------- REM TrueCrypt.exe [/a [devices|favorites]] [/b] [/c [y|n]] [/d [drive letter]] [/e] [/f] [/h [y|n]] [/k keyfile or search path] REM [/l drive letter] [/m {bk|rm|recovery|ro|sm|ts}] [/p password] [/q [background|preferences]] REM [/s] [/tokenlib path] [/v volume] [/w] REM REM TrueCrypt.exe [/a [devices|favorites]] REM [/b] REM [/c [y|n]] REM [/d [drive letter]] REM [/e] REM [/f] REM [/h [y|n]] REM [/k keyfile or search path] REM [/l drive letter] REM [/m {rm|ro|sm|ts}] REM [/p password] REM [/q [background|preferences]] REM [/s] REM [/v volume] REM [/w] REM REM /help or /? Display command line help. REM /volume or /v File and path name of a TrueCrypt volume to mount (do not use when dismounting). REM /letter or /l Driver letter to mount the volume as. When /l is omitted and when /a is used, the first free drive letter is used. REM /explore or /e Open an Explorer window after a volume has been mounted. REM /beep or /b Beep after a volume has been successfully mounted or dismounted. REM /auto or /a If no parameter, automount the volume. (/a devices), auto-mount all device/partition volumes. (/a favorites), auto-mount favorite REM /force or /f Forces dismount (IF the volume to be dismounted contains files being used) REM /keyfile or /k Specifies a keyfile or a keyfile search path. (/k c:\keyfile1.dat /k token://slot/SLOT_NUMBER/file/FILE_NAME) REM /tokenlib Use the specified PKCS #11 library for security tokens and smart cards. REM /cache or /c y or no parameter: enable password cache; n: disable password cache (e.g., /c n). REM /history or /h y or no parameter: enables saving history of mounted volumes; n: disables saving history of mounted volumes (e.g., /h n). REM /wipecache or /w Wipes any passwords cached in the driver memory. REM /password or /p The volume password. If the password contains spaces, use quotations (/p "My Pass"). Use (/p "") for empty password. REM /quit or /q Perform requested actions and exit (main TrueCrypt window not displayed). If preferences is specified as the parameter load/save options overriding command line. REM /q background launches the TrueCrypt Background Task (tray icon) unless it is disabled in the Preferences. REM /silent or /s If /q is specified, suppresses interaction with the user (prompts, error messages, warnings, etc.). If /q is not specified, this option has no effect. REM /mountoption or /m REM ro or readonly: Mount volume as read-only. REM rm or removable: Mount volume as removable medium. REM ts or timestamp: Do not preserve container modification timestamp REM sm or system: Without pre-boot authentication, mount a partition within system encryption (partition located on the encrypted system drive of another OS not running). REM bk or headerbak: Mount volume using embedded backup header. REM recovery: Do not verify checksums in the volume header. Should be used only when the volume header is damaged and cannot be mounted even with headerbak option. REM REM ---- plink ------------------------------------------------- REM plink [options] [user@]host [command] ("host" can also be a PuTTY saved session name) REM REM Options: REM -V Print version information and EXIT REM -v Show verbose messages (up to 3 times) REM -batch Disable all interactive prompts REM -ssh Force use of a ssh protocol REM -telnet Force use of a telnet protocol REM -rlogin Force use of a rlogin protocol REM -raw Force use of a raw protocol REM -load sessname Load settings from saved session 'sessname' REM -P port Connect to specified port REM -l user Connect with specified username REM -pw passwd Login with specified password REM -pgpfp Print PGP key fingerprints and EXIT REM -noagent Disable use of Pageant REM -agent Enable use of Pageant REM -D [listen-IP:]listen-port Dynamic SOCKS-based port forwarding REM -L [listen-IP:]listen-port:host:port Forward local port to REMote address REM -R [listen-IP:]listen-port:host:port Forward REMote port to local address REM -nc host:port Open tunnel in place of session (SSH-2 only) REM -X Enable X11 forwarding REM -x Disable X11 forwarding REM -A Enable agent forwarding REM -a Disable agent forwarding REM -t Enable pty allocation REM -T Disable pty allocation REM -1 Force use of SSH1 REM -2 Force use of SSH2 REM -4 Force use of IPv4 REM -6 Force use of IPv6 REM -C Enable compression REM -s Remote command is an SSH subsystem (SSH-2 only) REM -N Don't START a shell/command (SSH-2 only) REM -i key Private key file for authentication REM -m file Read REMote command(s) from file REM ---- attrib ------------------------------------------------- REM ATTRIB [+R | -R] [+A | -A ] [+S | -S] [+H | -H] [drive:][path][filename] [/S [/D]] REM REM + Sets an attribute. REM - Clears an attribute. REM R Read-only file attribute. REM A Archive file attribute. REM S System file attribute. REM H Hidden file attribute. REM [drive:][path][filename] Specifies a file or files for attrib to process. REM /S Processes matching files in the current folder and all subfolders. REM /D Processes folders as well. REM ---- ERASE ------------------------------------------------- REM ERASE [/P] [/F] [/S] [/Q] [/A[[:]attributes]] names REM REM names Specifies a list of one or more files or directories. IF a directory is specified, all files within will be deleted. REM REM /P Prompts for confirmation before deleting each file. REM /F Force deleting of read-only files. REM /S Delete specified files from all subdirectories. REM /Q Quiet mode, do not ask IF ok to delete on global wildcard REM /A Selects files to delete based on attributes REM attributes R Read-only files REM S System files REM H Hidden files REM A Files ready for archiving REM - Prefix meaning not REM ---- sc ------------------------------------------------- REM sc [ServerName] REM config [ServiceName] REM [type= {own | share | kernel | filesys | rec | adapt | interact type= {own | share}}] REM [START= {boot | system | auto | demand | disabled}] REM [error= {normal | severe | critical | ignore}] REM [binpath= BinaryPathName] REM [group= LoadOrderGroup] REM [tag= {yes | no}] REM [depend= dependencies] REM [obj= {AccountName | ObjectName}] REM [displayname= DisplayName] REM [password= Password] REM ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- REM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- REM ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- :EOF EXIT EXIT