ados Posted February 14, 2022 Share Posted February 14, 2022 Apologies for asking such a basic question but I've tried many different syntax corrections and I cannot get it to work. I'm trying to pass Get-wmiobject Win32_Product | where {($_.Name -Cnotlike "Sophos Anti-Virus" )} | Select-object IdentifyingNumber | ft -HideTableHeaders > C:\Temp\output.txt to PS and then retrieve the output as well. The latter I have sorted it just the syntax I cannot get working. I have tried putting it into a the run directly and saving it as a string to a variable to then use within the run but no good. The commands work in PS directly of course, I'm sure its the quoting, note that Sophos Anti-Virus must be double quoted for PS to accept. Here is my latest revision: $PS = 'powershell -command Get-wmiobject Win32_Product | where {($_.Name -Cnotlike "Sophos Anti-Virus" )} | Select-object IdentifyingNumber | ft -HideTableHeaders > C:\Temp\output.txt' ;Get the GUI for Trend $GUI = Runwait(@ComSpec & " /c " & $PS, "", @SW_hide , $stdout_child) $Output = StdoutRead ($GUI) MsgBox (0, "Test", $Output) Link to comment Share on other sites More sharing options...
ad777 Posted February 14, 2022 Share Posted February 14, 2022 (edited) @ados this should work for ya: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- #include <AutoitConstants.au3> ; Script Start - Add your code below here Local $PS = 'Get-wmiobject Win32_Product | where {($_.Name -Cnotlike "Sophos Anti-Virus" )} | Select-object IdentifyingNumber | ft -HideTableHeaders > C:\Temp\output.txt' $GUI = Run("powershell " & $PS, "", @SW_HIDE, $stdout_child) ;$GUI = Runwait(@ComSpec & " /c " & $PS, "", @SW_SHOW , $stdout_child) While 1 $Output = StdoutRead($GUI) if $Output <> "" Then MsgBox(0, "Test", $Output) if StringLen($Output) > 255 Then ExitLoop WEnd Edited February 14, 2022 by ad777 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
ados Posted February 14, 2022 Author Share Posted February 14, 2022 21 minutes ago, ad777 said: @ados this should work for ya: #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.5 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- #include <AutoitConstants.au3> ; Script Start - Add your code below here Local $PS = 'powershell -command Get-wmiobject Win32_Product | where {($_.Name -Cnotlike "Sophos Anti-Virus" )} | Select-object IdentifyingNumber | ft -HideTableHeaders > C:\Temp\output.txt' $GUI = Run("powershell " & $PS, "", @SW_HIDE, $stdout_child) ;$GUI = Runwait(@ComSpec & " /c " & $PS, "", @SW_SHOW , $stdout_child) While 1 $Output = StdoutRead($GUI) if $Output <> "" Then MsgBox(0, "Test", $Output) if StringLen($Output) > 255 Then ExitLoop WEnd Bugger, didn't work. Causes the script to infinitely wait and you never see a message box. Removed the loop and it then gives a blank message box. Additionally, the output txt file is empty but if I run the command within PS it outputs. 😔 Link to comment Share on other sites More sharing options...
abberration Posted February 14, 2022 Share Posted February 14, 2022 I wasn't able to get it working, but I was able to get message boxes going and was able to read error messages (maybe the error messages might help you). I played with the working directory. Also, I know you can use /k instead of /c, but I'm not sure what is the difference. Maybe playing with those variables might help. #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $sOutput = "" $PS = 'powershell -command Get-wmiobject Win32_Product | where {($_.Name -Cnotlike "Sophos Anti-Virus" )} | Select-object IdentifyingNumber | ft -HideTableHeaders > C:\Temp\output.txt' $iPID = Run(@ComSpec & " /c " & $PS, @SystemDir, @SW_MINIMIZE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput) WEnd $sOutput = '' While 1 $sOutput &= StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput) WEnd Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
ados Posted February 15, 2022 Author Share Posted February 15, 2022 1 hour ago, abberration said: I wasn't able to get it working, but I was able to get message boxes going and was able to read error messages (maybe the error messages might help you). I played with the working directory. Also, I know you can use /k instead of /c, but I'm not sure what is the difference. Maybe playing with those variables might help. #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Local $sOutput = "" $PS = 'powershell -command Get-wmiobject Win32_Product | where {($_.Name -Cnotlike "Sophos Anti-Virus" )} | Select-object IdentifyingNumber | ft -HideTableHeaders > C:\Temp\output.txt' $iPID = Run(@ComSpec & " /c " & $PS, @SystemDir, @SW_MINIMIZE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput) WEnd $sOutput = '' While 1 $sOutput &= StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput) WEnd The select-object failing is indicating that the commands passed are not getting processed by PS correctly due to something in the syntax not working from Autoit to PS. Link to comment Share on other sites More sharing options...
Nine Posted February 15, 2022 Share Posted February 15, 2022 @ados Why don't you get the information you want directly from WMI ! There is no need to go thru PS. You can then create the report you want easily using AutoIt. Example : #include <Constants.au3> #include <Array.au3> Opt("MustDeclareVars", True) ReadProduct("Windows Live Writer") Func ReadProduct($sProductName) Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Product WHERE Name = "' & $sProductName & '"') If Not IsObj($colItems) Then Exit MsgBox(0, "", "Not an object") If Not $colItems.count Then Exit MsgBox(0, "", "Product not found") For $oItem In $colItems ConsoleWrite($oItem.Name & @CRLF) ConsoleWrite($oItem.InstallDate & @CRLF) ConsoleWrite($oItem.IdentifyingNumber & @CRLF) Next EndFunc ;==>ReadProduct Danyfirex 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now