batch
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
batch [2013/01/13 15:05] – skipidar | batch [2020/12/27 20:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Fallpits ===== | ||
+ | < | ||
+ | #when using variables no empty spaces after equal | ||
+ | VAR TEST1=" | ||
+ | VAR TEST2 ="VAR WILL BE EMPTY" | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== call ===== | ||
+ | To call another *.bat use | ||
+ | < | ||
+ | call " | ||
+ | </ | ||
+ | |||
+ | ===== start ===== | ||
+ | To start a programm in the console, and pass it some **parameters with empty spaces** use the following syntax: | ||
+ | |||
+ | < | ||
+ | start " | ||
+ | </ | ||
+ | |||
+ | The first argument of " | ||
+ | |||
+ | **/B** flag makes windows not creating a new window. | ||
+ | |||
+ | Documentation start command: http:// | ||
+ | |||
+ | |||
+ | Start cm with a command works like this. Use **/k** to start cmd with a commad. | ||
+ | < | ||
+ | start cmd /k " | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Printers ===== | ||
+ | |||
+ | Put the following into the " | ||
+ | < | ||
+ | rundll32 printui.dll, | ||
+ | </ | ||
+ | |||
+ | |||
+ | < | ||
+ | :: delete network printer per batch | ||
+ | rundll32 printui.dll, | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | :: install a network printer per batch | ||
+ | rundll32 printui.dll, | ||
+ | </ | ||
+ | |||
+ | == Counter == | ||
+ | |||
+ | To use Counters - deplayed expanation must be used in batch. | ||
+ | The Variables are then translated to numers eveny loop. | ||
+ | * It must be enabled by **setlocal ENABLEDELAYEDEXPANSION** | ||
+ | * variables are loaded by **!var!** von %var% | ||
+ | |||
+ | |||
+ | < | ||
+ | setlocal ENABLEDELAYEDEXPANSION | ||
+ | |||
+ | set /A cnt=1 | ||
+ | |||
+ | for %%f in (*.cer) do ( | ||
+ | echo %%~nf | ||
+ | set /A cnt=cnt+1 | ||
+ | echo !cnt! | ||
+ | ) | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | === Commands === | ||
+ | |||
+ | == SUBST== | ||
+ | Create a virtual disk from a LOCAL folder | ||
+ | < | ||
+ | subst z: b: | ||
+ | |||
+ | # delete | ||
+ | subst z: b: | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | === SCRIPT to find java process by command line argments === | ||
+ | |||
+ | Name it findJavaProcessByCommandline.bat | ||
+ | Usage: | ||
+ | |||
+ | < | ||
+ | call findJavaProcessByCommandline.bat javaCommandLinePart | ||
+ | if errorlevel 1 echo NoFindings & exit /b 1 | ||
+ | </ | ||
+ | |||
+ | |if errorlevel 1 | check result of nested script. 1 if nothing found| | ||
+ | |echo NoFindings | Echo| | ||
+ | |& exit /b 1| and exits the parent script. Instead you can do whatever you want with this info | | ||
+ | |||
+ | < | ||
+ | @echo off | ||
+ | |||
+ | :: check if empty | ||
+ | IF [%1] == [] GOTO noarg | ||
+ | |||
+ | :: use the argument | ||
+ | set likeString=%1 | ||
+ | |||
+ | |||
+ | setlocal EnableDelayedExpansion | ||
+ | set processIdFinding= | ||
+ | for /f %%i in ('wmic process where " | ||
+ | set processIdFinding=!processIdFinding!%%i | ||
+ | ) | ||
+ | |||
+ | if " | ||
+ | goto nofindings | ||
+ | ) else ( | ||
+ | goto findings | ||
+ | ) | ||
+ | |||
+ | :nofindings | ||
+ | echo Nothing Found | ||
+ | exit /b 1 | ||
+ | |||
+ | :findings | ||
+ | echo Finding: %processIdFinding% | ||
+ | exit /b 0 | ||
+ | |||
+ | :noarg | ||
+ | echo Please provide the Stringto be searched withing java process commandline as an argument | ||
+ | exit /b 1 | ||
+ | </ | ||