Hopefully "ScriptingTipsAndTricks" helps you with your batch file or vbscript scripting :-)
[Bottom][Contents][Prev]: WaitForTime() - delay until a chosen time[Next]: VBSCRIPT Files
\->Batch Files->WMIC.exe - WMI From Windows Command Line (batch files)

WMIC.exe [WMI From Windows Command Line (batch files)].cmd

This example uses Windows Management Instrumentation (WMI) via the "WMIC.exe" command

[anchor]

The Code for: "WMIC.exe [WMI From Windows Command Line (batch files)].cmd"

This is the example, a shortcut was installed to this code :

@echo off
::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
:: $Header:   C:/DBAREIS/Projects.PVCS/Win32/ScriptingTipsAndTricks/EXAMPLE[cmd].WMIC.exe [WMI From Windows Command Line (batch files)].cmd.pvcs   1.0   29 Jun 2014 12:51:22   USER "Dennis"  $
::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

::###########################################################################
::### Note WMIC.exe output is UNICODE but Windows batch needs it in ASCII ###
::###########################################################################
@setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
cls

::--- Run the wmic.exe command -----------------------------------------------
set TmpWmicResults=%TEMP%\wmic-UNICODE_Windows-needs-ASCII.txt
set   WmicResults=%TEMP%\wmic.txt
set CMD=wmic.exe /FAILFAST:ON ComputerSystem GET Domain,Name,Model,UserName,SystemType,Manufacturer /value
echo C:\^> %CMD%
   %CMD% > "%TmpWmicResults%" 2>&1
type "%TmpWmicResults%" > "%WmicResults%" 2>&1
type "%WmicResults%"
echo         ----[ end of file "%WmicResults%" ] ----

::--- Process the WMI results ------------------------------------------------
echo.&echo.
for /F "usebackq delims=" %%l in ("%WmicResults%") do call :ProcessWmicExeLine "%%l"

::--- Display as "Latitude E6320 (Dell Inc. X86-based PC)" ------------------
echo EXTRACTED INFO: %WMIC_MODEL% (%WMIC_Manufacturer% %WMIC_SystemType%)
goto :EOF


::============================================================================
:ProcessWmicExeLine
::============================================================================
    ::--- Process the line if its not empty ----------------------------------
    if "%~1" == "" goto :EOF
    set WNAME=
    set  WKEY=
    for /F "tokens=1,2 delims==" %%A in ("%~1") do set WNAME=%%A& set WKEY=%%B
    if "%WKEY%" == "" goto :EOF
    set WMIC_%WNAME%=%WKEY%
goto :EOF


::###########################################################################
::### Note WMIC.exe output is UNICODE but Windows batch needs it in ASCII ###
::###########################################################################



;--- Getting Help --------------------
Switches (/FAILFAST:ON): http://technet.microsoft.com/en-us/library/cc787035(v=ws.10).aspx
C:\> wmic /?
C:\> wmic logicaldisk /?
C:\> wmic logicaldisk GET /?
C:\> wmic CsProduct list full





;---Query local disk info (http://en.code-bude.net/2013/02/23/show-all-drives-in-command-prompt/) -------------
C:\> wmic logicaldisk get name, Description
Description       Name
Local Fixed Disk  C:
CD-ROM Disc       D:

C:\> wmic logicaldisk get name, Description /VALUE
Description=Local Fixed Disk
Name=C:

Description=CD-ROM Disc
Name=D:

C:\> wmic logicaldisk where DriveType=3 GET Name /VALUE

Name=C:


C:\> wmic CsProduct GET Vendor,Name,Version,IdentifyingNumber /VALUE
C:\> wmic ComputerSystem GET Domain,Name,Model,UserName,SystemType,Manufacturer /value






;---------------------------------------------------------------------
;--- Get Remote Computer Details -------------------------------------
;---------------------------------------------------------------------
C:\> WMIC /NODE: 13.216.210.121 COMPUTERSYSTEM GET NAME /VALUE

Name=SOMESERVERNAME

Please note that that I am not trying to show how great I am by producing batch files 9,000 characters long on one line that no one will understand or be able to debug when they go wrong. I am going out of my way to comment the code and make it verbose so beginners and advanced users will both benefit. I don't claim to be an expert that knows everything, if I'm wrong or make a mistake then please contact me and let me know :-)


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: WaitForTime() - delay until a chosen time[Next]: VBSCRIPT Files


ScriptingTipsAndTricks© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Sunday September 07 2014 at 12:50pm
Visit ScriptingTipsAndTricks's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.