Difference between revisions of "Windows batch"
Jump to navigation
Jump to search
Line 41: | Line 41: | ||
*[http://technet.microsoft.com/en-us/library/bb490890.aspx Command-line reference A-Z] For tylda parameters look for FOR | *[http://technet.microsoft.com/en-us/library/bb490890.aspx Command-line reference A-Z] For tylda parameters look for FOR | ||
*[http://stackoverflow.com/questions/112055/what-does-d0-mean-in-a-windows-batch-file What does %~d0 mean in a Windows batch file?] | *[http://stackoverflow.com/questions/112055/what-does-d0-mean-in-a-windows-batch-file What does %~d0 mean in a Windows batch file?] | ||
[[Category:Windows]] |
Revision as of 18:58, 2 May 2015
Fciv - integration check
IF and ELSE
- The else needs to be on the same "line" as the if. From IF /? 'The ELSE clause must occur on the same line as the command after the IF.'
if "zz"=="TRUE" ( copy /a zz + /a ee=/a zz ) else ( copy /a e + /a %TMP%=/a e )
- Environment variables in batch files are expanded when a line is parsed.
In the case of blocks delimited by parentheses (as your if defined) the whole block counts as a "line" or command and it is read once. This means that all occurrences of %FOO% are replaced by their values before the block is run. Therefore %FOO% will be replaced by nothing as it was not set.
To solve this you can enable delayed expansion:
setlocal enabledelayedexpansion
Delayed expansion causes variables delimited by exclamation marks (!) to be evaluated on execution instead of parsing which will ensure the correct behavior in our case:
if not defined BAR ( set FOO=1 echo Foo: !FOO! )
Text manipulation
- color 0a - changes text to green
- mode con: cols=80 lines=50 - changes cmd.exe window, no scroll available, type mode to display the current settings
netsh - import wireless profile
- Export profile
Netsh wlan export profile folder= PathAndFileName [[name=] ProfileName] [[interface=] InterfaceName] [[key=] clear] Netsh wlan export profile folder=%USERPROFILE%\Downloads\Wifiprofiles name=Guest_wireless interface="Wireless Network Connection"
- Import profile
Netsh wlan add profile filename= PathAndFileName [[interface=]InterfaceName] [[user=]{all|current}] Netsh wlan add profile filename="Wireless Network Connection-Guest_wireless.xml" interface="Wireless Network Connection" user=all
References
- Using batch parameters
- Command-line reference A-Z For tylda parameters look for FOR
- What does %~d0 mean in a Windows batch file?