StdOut for Online Drivers

Started by spl, November 08, 2024, 04:41:35 AM

Previous topic - Next topic

spl

Again, sure it could be done in pure WB but this works
;Dislay Online Drivers
;save as ..\StdOut_Drivers.wbt
;Stan Littlefield 11/08/2024
;==========================================================
Gosub udfs
drivers = "C:\temp\drivers.csv"
args = $"
$drivers = Get-WindowsDriver –Online -All | Select Driver,Classname,BootCritical,Date,Version |
ConvertTo-Csv -NoTypeInformation | Out-File -FilePath |drivers|
$"
args = StrReplace(args,"|drivers|",drivers)
cmd="Powershell"
msg='Online Drivers'

BoxOpen("Running...",cmd:" ":args:@LF:"PLEASE WAIT...MAY TAKE SOME TIME")
TimeDelay(2)
vals = Get_stdout():@LF:"Script Completed"
Message(msg,vals) 

If FileExist(drivers) Then Run("notepad.exe",drivers)
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
;==========================================================



Stan - formerly stanl [ex-Pundit]