WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: spl on September 26, 2026, 04:53:00 AM

Title: Another CimInstance
Post by: spl on September 26, 2026, 04:53:00 AM
Haven't tried this with direct WB WMI code. Pretty interesting class, probably needs datetime and other formatting and better understanding of properties involved - but worked fine on my Win10 Surface Pro.
;Std_Out AntiMalWare
;Stan Littlefield 9/26/2026
;========================================================================================================================
Gosub udfs
args = $"Get-CimInstance -Namespace root\Microsoft\SecurityClient -ClassName AntimalwareHealthStatus |
Select-Object ProductStatus,*end,*source,*version,*enabled | Tee-Object -variable t
$"

cmd="Powershell"                                                                                                       
msg='AntiMalWare Check'
BoxOpen(msg,cmd:" ":args:@LF:"PLEASE WAIT...MAY TAKE SOME TIME")
TimeDelay(2)
vals = Get_stdout()
BoxShut()
Message("AntiMalware Status Check",vals)
Exit
;======================================================================
:udfs
#DefineSubroutine Get_stdout()
ObjectClrOption("useany","System")
objInfo = ObjectClrNew("System.Diagnostics.ProcessStartInfo")
Output=""
timeOut = ObjectType("I2",5000)
objInfo.FileName = cmd
objInfo.RedirectStandardError = ObjectType("BOOL",@TRUE)
objInfo.RedirectStandardOutput = ObjectType("BOOL",@TRUE)
objInfo.UseShellExecute = ObjectType("BOOL",@FALSE)
objInfo.CreateNoWindow = ObjectType("BOOL",@TRUE)
objInfo.Arguments = args
oProcess = ObjectClrNew("System.Diagnostics.Process")
oProcess.StartInfo = objInfo
oProcess.Start()
oProcess.WaitForExit(timeout)
STDOUT = oProcess.StandardOutput.ReadToEnd()
STDERR = oProcess.StandardError.ReadToEnd()
Output = Output:STDOUT:@CRLF
If STDERR<>""
  Output = Output:"STDERR:":STDERR:@CRLF
Endif
oProcess = 0
objInfo = 0

Return (Output)
#EndSubroutine
Return
;==========================================================
Title: Re: Another CimInstance
Post by: JTaylor on September 26, 2026, 06:47:47 AM
Works well.

Jim
Title: Re: Another CimInstance
Post by: spl on September 26, 2026, 08:19:07 AM
Thanks Jim. You could add 'name' to the list of select-object, and I did appreciate use of wildcard selection on properties.