Category Archives: Coding

BAT file (some commands)

ECHO : write on CMD (MS DOS) screen

@ECHO : @ at the beginning mean “do not show this command on running screen”

@REM :  “NOTE sentence” – write a note in a batch file.

:POINT1  : Denote a point in batch file

GOTO POINT1 : jump to POINT1, skip all command below GOTO and above POINT1

@ECHO This text > file.txt : overwrite file

@ECHO Thi text >> file.txt : append to the file

%VARIABLE%  : variable in batch file, locate between %…%

@SET VAR=This Value   : assign variable in batch file

@SET VAR=%VAR% and This Text    (new VAT is “This Value and This Text”)

@SET VAR=2

@SET /A VAR=%VAR%+1 (/A mean attribute, result is VAR is 2 + 1 = 3)

@IF %VAR%==0 (command) ELSE (command)

@IF %VAR%==0 DO (command)

@ECHO This Text>File.txt  :  ECHO command writes text to file with ANSI encoding

@wmic.exe /APPEND:File.txt /NODE:%PC_Name% CPU GET SYSTEMNAME  :  WMIC command writes text to file with UNICODE encoding.

 

WMIC (Windows Management Instrumentation Command) example

WMIC.exe

Windows Management Instrumentation Command.
Read a huge range of information about local or remote computers. Also provides a way to make configuration changes to multiple remote machines. WMIC is available on Vista/Windows 7, Windows XP Professional, but not Windows XP Home.

Examples:

WMIC /output:”%computername%.txt” MEMORYCHIP where “memorytype=17” get Capacity

WMIC /node:remote_computer PROCESS call create “netstat.exe -ano > C:\output.txt”

Continue reading

Windows wmic command line command

Windows wmic command line command

Quick links

About wmic
Availability
Wmic syntax
Wmic examples

About wmic

Short for WMI console, wmic is a command line command to query WMI entries.

Availability

The wmic command is an external command that is available in the below Microsoft operating systems as wmic.exe.

Windows XP professional
Windows 2003
Windows Vista
Windows 7
Windows 8

Continue reading

Escape Characters in DOS (Special characters in DOS)

All DOS versions interpret certain characters before executing a command.
Some well know examples are the percent sign ( % ), and the redirection symbols ( < | > ).

Windows 95/98 and NT, and OS/2 too, also interpret double quotes ( " ) and ampersands ( & ), as shown in theConditional Execution page.

In batch files, the percent sign may be “escaped” by using a double percent sign ( %% ).
That way, a single percent sign will be used as literal within the command line, instead of being further interpreted.

In Windows 95/98 and NT, and OS/2 too, redirection symbols may be escaped by placing them between double quotes ( ">" ).
However, the quotes themselves will be passed to the command too, unlike the double percent sign.

Windows NT and OS/2 also allow the use of carets ( ^ ) to escape special characters. Even linefeeds can be escaped this way, as is shown in the Useless Tips page.

If you intend to “nest” commands with escaped characters, you may need to escape the escape character itself too.
In general, that won’t make it any easier to read or debug your batch files, however.

Since the introduction of delayed variable expansion a new challenge is to escape exclamation marks, the “delayed” version of the percent sign.
Unlike percent signs, that can be escaped by doubling them, exclamation marks cannot be escaped by adding an extra exclamation mark.
Nor does a caret before the exclamation mark work, unless quoted (i.e. ECHO ^! will fail to display an exclamation mark, whereas ECHO "^!" will display a quoted exclamation mark: "!").
Jaime Ramos sent me this link where the solution can be found: use ^^!.
The trick is that a single caret will be used to escape the exclamation mark in the firt “pass” of command line interpretation, but delayed variable expansion adds a second “pass” where the exclamation mark will be interpreted. If you don’t get it, never mind, just remember the double caret before the exclamation mark.

Using FIND to search files or standard output for a string containing doublequotes used to be a pain… I often usedFINDSTR instead, in these cases.
Robert Cruz explained to me that in this particular case only you need to escape doublequotes by doublequotes, i.e. a single doublequote must be replaced by 2 doublequotes.
He also sent me this link on the subject.

 

Summary

Escape Characters
Character to be escaped Escape Sequence Remark
% %% May not always be required in doublequoted strings, just try
^ ^^ May not always be required in doublequoted strings, but it won’t hurt
& ^&
< ^<
> ^>
| ^|
' ^' Required only in the FOR /F “subject” (i.e. between the parenthesis),unless backq is used
` ^` Required only in the FOR /F “subject” (i.e. between the parenthesis), ifbackq is used
, ^, Required only in the FOR /F “subject” (i.e. between the parenthesis), even in doublequoted strings
; ^;
= ^=
( ^(
) ^)
! ^^! Required only when delayed variable expansion is active
" "" Required only inside the search pattern of FIND
\ \\ Required only inside the regex pattern of FINDSTR
[ \[
] \]
" \"
. \.
* \*
? \?