Does this work...
Code: Select all
wmic /?
if errorlevel 1 echo.Not available
Moderator: DosItHelp
Code: Select all
wmic /?
if errorlevel 1 echo.Not available
Code: Select all
if exist "%systemroot%\system32\wbem\wmic.exe" (echo:WMIC is installed.) else echo:WMIC is not installed.
orange_batch wrote:WMIC is found in a static directory.
Code: Select all
C:\>for %a in (wmic.exe) do @echo %~$path:a
C:\Windows\System32\wbem\WMIC.exe
Code: Select all
for %%a in (wmic.exe) do set wmicPath=%%~$path:a
if defined wmicPath (echo WMIC is installed) else echo WMIC is not installed
What is a good way to check if wmic is available on a machine
Code: Select all
Please wait while WMIC compiles updated MOF files.
Code: Select all
:ERR.Get.WMIC ( /Alias: "STRING" /ToWorkFile /Int_ERR )
::
:: SJAB v1.142c beta
::
:: Checks wheter WMIC can process @Alias
::
::INPUT:
:: @Alias STRING Required; Alias to check
:: @ToWorkFile STRING Optional; Save querry results to WorkFile
:: @Int_ERR STRING Optional; Halt on error
::
::OUTPUT
:: @WorkFile_Succes BYVAL Return if @ToWorkFile; Handle to WorkFile
:: @FullPathFile.WorkFile_Succes BYVAL Return if @ToWorkFile; @FullPathFile to WorkFile
:: @ERR BYVAL Return; 0 for succes, 1 for error
::
SetLocal
::(
::set "Debug.Sub=!Sub.%Sub.Depth%.Name!"
::(
::%Debug% "" "inside !Sub.%Sub.Depth%.Name! Sub.!Sub.Depth!.Par.AsIS:" &echo.!Sub.%Sub.Depth%.Par.AsIS!_
set "Sub.!Sub.Depth!.Use=:ERR.Get.WMIC ( /Alias: "STRING" /Int_ERR )"
::)
::%Debug% "PROC PAR"
::(
set "PAR.FIX=Alias"
set "PAR.OPT=ToWorkFile Int_ERR"
%PROC.PAR.FAST% "()"
::%Debug.Equals% for %%! in ( Alias ToWorkFile Int_ERR ) do echo. %%~!=!%%~!!_
::)
::%Debug% "VALID"
::(
for %%! in ( Alias ) do %ERR.Chk.IsDefined.TokenSTR% %()% >nul
for %%! in (
"WorkFile_Succes"
"WorkFile_Error"
"WorkFile_Int_WMIC"
) do (
%OpenWorkFile% "()"
::
set "%%~!=!WorkFile!"
)
::%Debug.Equals% for %%! in ( WorkFile_Succes WorkFile_Error WorkFile_Int_WMIC ) do echo. %%~!=!%%~!!_
::)
::%Debug% "Perform"
::(
::%Debug% " WinWaitClose: 'INT_WMIC'"
::(
%WinWaitClose% /Title: "INT_WMIC" /File: "CMD.EXE"
::)
::%Debug% " Intercept 'WMIC.EXE' error: 'lockup'"
::(
for %%! in (
"!FullPath.WorkFile!\WorkFile.!WorkFile_Int_WMIC!.CMD"
) do > "%%~!" (
::
echo.@echo off ^&SetLocal EnableExtensions EnableDelayedExpansion
echo.
echo.:INIT ^(^)
echo.::^(
echo. :: 120 secs * 18 = 2160 ticks
echo. "!FullPathFile.STACKEY.COM!" {WAIT=2160}
echo.::^)
echo.
echo.:MAIN ^(^)
echo.::^(
echo. taskKill.EXE /t /f /im "WMIC.EXE"
echo. ::
echo. 2^>nul tasklist /nh ^|^>nul findstr.EXE /i /c:"WMIC.EXE" ^&^&goto :MAIN "^(^)"
echo.::^)
echo.
echo.:EXIT ^(^)
echo.::^(
echo.::
echo.goto :eof ^(^)
echo.::^)
)
::
start "INT_WMIC" /low /min /D "!SystemROOT!" "%comspec%" /c "!FullPath.WorkFile!\WorkFile.!WorkFile_Int_WMIC!.CMD"
::)
::%Debug% " Querry 'WMIC.EXE' service: '!Alias!'"
::%Debug.Equals% WMIC.EXE !Alias!
::%Debug.Equals% pause
::(
set /a ERR.MEM = 1
::
for %%? in (
"!FullPath.WorkFile!\WorkFile.!WorkFile_Error!.TMP"
) do for %%! in (
"!FullPath.WorkFile!\WorkFile.!WorkFile_Succes!.TMP"
) do (
2> "%%~?" 1> "%%~!" WMIC.EXE !Alias!
::
for /f "tokens=*" %%! in (
'type "%%~!"'
) do set /a ERR.MEM = 0
::
for /f "tokens=*" %%! in (
'type "%%~?"'
) do set /a ERR.MEM = 1
::
if !ERR.MEM! equ 0 (
::
set "?="
::
set /p ?=< "!FullPath.WorkFile!\WorkFile.!WorkFile_Succes!.TMP"
::
set "MEM=!?!"
::
set "?=!?:Please wait while WMIC compiles updated MOF files.=!"
::
if /i ["!?!"] neq ["!MEM!"] (
::
1> "%%~!" WMIC.EXE !Alias!
)
)
)
::%Debug.Equals% echo. WorkFile_Error &type "!FullPath.WorkFile!\WorkFile.!WorkFile_Error!.TMP"
::%Debug.Equals% echo. WorkFile_Succes &type "!FullPath.WorkFile!\WorkFile.!WorkFile_Succes!.TMP"
::%Debug% " ERR.MEM=!ERR.MEM!_"
::)
for %%! in (
"WorkFile_Error"
"WorkFile_Int_WMIC"
) do (
set "WorkFile=!%%~!!"
::
%CloseWorkFile% %()% >nul
)
for %%! in (
"WorkFile_Succes"
) do (
set "WorkFile=!%%~!!"
::
if not defined ToWorkFile (
::%Debug% " Closing WorkFile_Succes"
%CloseWorkFile% %()% >nul
)
)
::%Debug% " Terminate intercept: 'lockup'"
::(
%WinWaitOpen% /Title: "INT_WMIC" /File: "CMD.EXE" /Timeout: "30"
::
if !ERR! equ 0 %ProcessClose% /Title: "INT_WMIC" /File: "CMD.EXE"
::)
set /a ERR = !ERR.MEM!
::
if !ERR! neq 0 if defined Int_ERR (
::
%ERR.Set.THIS% "'WMIC.EXE' service error:" "Alias:!Alias!_ ^!"
)
::)
::
::%Debug% /Pause " WorkFile_Succes=!WorkFile!_" " ERR=!ERR!_" "outside !Sub.%Sub.Depth%.Name!"
(
EndLocal
set "WorkFile_Succes=%WorkFile_Succes%"
set "FullPathFile.WorkFile_Succes=!FullPath.WorkFile!\WorkFile.!WorkFile_Succes!.TMP"
set /a ERR = %ERR%
)
goto :eof ()
::)