WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: spl on February 16, 2026, 06:33:29 AM

Title: ComputerInfo - revisted
Post by: spl on February 16, 2026, 06:33:29 AM
The STDOut script below extracts Computer Information with a PS Format-Custom display. It is verbose and not the best candidate for parsing, but completely breaks down the element object. In the header note the suggestion to run the script as 64-bit WB. In 32-bit mode, elements like the ProductID and RegisteredOwner are blank, filled in if run in 64-bit. Found that interesting.
;Get Extended Information for a PC - using PS Format-Custom
;Stan Littlefield 1/29/2026
;updated 2/15/2026
;NOTE: Run as 64-bit to include elements like ProductID or RegisteredOwner
;========================================================================================================================
Gosub udfs
file = Dirscript():"pcinfo.txt"
If fileexist(file) Then filedelete(file)
args = "Get-ComputerInfo | Format-Custom -Depth 1"
cmd="Powershell"
msg='Extended Computer Information'
BoxOpen("Running...",cmd:" ":args:@LF:"PLEASE WAIT...MAY TAKE SOME TIME")
TimeDelay(2)
vals = Get_stdout()
vals = StrReplace(StrTrim(StrReplace(vals, @CRLF, @TAB)), @TAB, @CRLF)
;======================================================================
FilePut(file,vals)
If FileExist(file) Then Run("notepad.exe",file)
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
BoxShut()
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
;==========================================================