GAM Posted June 23, 2009 Share Posted June 23, 2009 Am writing a script to run a command using AutoIT that checks the existence of Particular Process ID. But am getting some errors with the RUN command (THE COMMAND IS CALLING THE POWERSHELL SCRIPTS OUTPUT). Here's the script IN autoit... ------------------------------------------------------------------------------------------------------------------------------------------ $ESXPid = 936 $Cmd = "Get-WmiObject win32_process | where {" & $ & " _.ProcessID -eq " & $ESXPid & "} | Format-Table ProcessName, ProcessID, PageFileUsage, ThreadCount, HandleCount, PageFileUsage, ReadOperationCount" Run($Cmd) ------------------------------------------------------------------------------------------------------------------------------------------- The error message is returning is "Badly formated variable or macro.: " The command thats in the variable $Cmd is POWERSHELL'S command. Can someone please help?? Neil Link to comment Share on other sites More sharing options...
Juvigy Posted June 23, 2009 Share Posted June 23, 2009 I am not familiar with this "powershell" but if it is supposed to type this in the "CMD" console you should use something like Run(@ComSpec & " /c " & '$Cmd') Link to comment Share on other sites More sharing options...
GodlessSinner Posted June 23, 2009 Share Posted June 23, 2009 (edited) I think you don't need to use cmd.exe for checking process ID for existence.... You just can use this: Global $exist = 0 $ID = "936" $list = ProcessList() for $i = 1 to $list[0][0] If $list[$i][1] = $ID Then msgbox(0, "Process exist!", "Its named:" & $list[$i][0]) $exist = 1 EndIf next If Not $exist Then MsgBox(0,"Process not found!","Process with ID:"& $ID & " not exist.") EndIf Edited June 23, 2009 by Vitas _____________________________________________________________________________ Link to comment Share on other sites More sharing options...
GAM Posted June 23, 2009 Author Share Posted June 23, 2009 Thanks Vitas, infact am checking for many counters like as stated below... ProcessName ProcessID PageFileUsage ThreadCount HandleCount PageFileUsage ReadOperationCount ReadTransferCount I think AutoIt doesn't support this so I opted for Powershell. Can you please let me know if I can get the above counters using AUTOIT? Neil Link to comment Share on other sites More sharing options...
99ojo Posted June 23, 2009 Share Posted June 23, 2009 Thanks Vitas, infact am checking for many counters like as stated below...ProcessNameProcessIDPageFileUsageThreadCountHandleCountPageFileUsageReadOperationCountReadTransferCountI think AutoIt doesn't support this so I opted for Powershell. Can you please let me know if I can get the above counters using AUTOIT?Hi,1) Just have a look at ProcessGetStats (see helpfile). I think only the pagefileusage is missed. ProcessName and ProcessID you get with ProcessList, the rest with ProcessGetStats.2) This may you help with your powershellcommand: http://www.microsoft.com/technet/scriptcen...07/hey0411.mspx;-))Stefan Link to comment Share on other sites More sharing options...
spudw2k Posted June 23, 2009 Share Posted June 23, 2009 There are numerous scripts on this forum that show how to perform WMI queries...which is all that the powershell script is doing. Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF  Link to comment Share on other sites More sharing options...
Ascend4nt Posted June 23, 2009 Share Posted June 23, 2009 Thanks Vitas, infact am checking for many counters like as stated below...ProcessNameProcessIDPageFileUsageThreadCountHandleCountPageFileUsageReadOperationCountReadTransferCountI think AutoIt doesn't support this so I opted for Powershell. Can you please let me know if I can get the above counters using AUTOIT?Check out my PDH Performance Counters (see my sig. below). You can gather all that info through them.I've got more coming actually, something of an informational mock-Task Manager is in the works (just don't expect it right away.. a bit of work to do on the GUI and cleaning up & debugging code)P.S. I clicked this thread hoping there really was a 'Rum' command My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs |Â Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) |Â Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
GodlessSinner Posted June 23, 2009 Share Posted June 23, 2009 Can you please let me know if I can get the above counters using AUTOIT?ok. _____________________________________________________________________________ Link to comment Share on other sites More sharing options...
GEOSoft Posted June 23, 2009 Share Posted June 23, 2009 expandcollapse popup$wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output &= "Computer: " & $strComputer & @CRLF $Output &= "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output &= "Caption: " & $objItem.Caption & @CRLF $Output &= "CommandLine: " & $objItem.CommandLine & @CRLF $Output &= "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output &= "CreationDate: " & WMIDateStringToDate($objItem.CreationDate) & @CRLF $Output &= "CSCreationClassName: " & $objItem.CSCreationClassName & @CRLF $Output &= "CSName: " & $objItem.CSName & @CRLF $Output &= "Description: " & $objItem.Description & @CRLF $Output &= "ExecutablePath: " & $objItem.ExecutablePath & @CRLF $Output &= "ExecutionState: " & $objItem.ExecutionState & @CRLF $Output &= "Handle: " & $objItem.Handle & @CRLF $Output &= "HandleCount: " & $objItem.HandleCount & @CRLF $Output &= "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output &= "KernelModeTime: " & $objItem.KernelModeTime & @CRLF $Output &= "MaximumWorkingSetSize: " & $objItem.MaximumWorkingSetSize & @CRLF $Output &= "MinimumWorkingSetSize: " & $objItem.MinimumWorkingSetSize & @CRLF $Output &= "Name: " & $objItem.Name & @CRLF $Output &= "OSCreationClassName: " & $objItem.OSCreationClassName & @CRLF $Output &= "OSName: " & $objItem.OSName & @CRLF $Output &= "OtherOperationCount: " & $objItem.OtherOperationCount & @CRLF $Output &= "OtherTransferCount: " & $objItem.OtherTransferCount & @CRLF $Output &= "PageFaults: " & $objItem.PageFaults & @CRLF $Output &= "PageFileUsage: " & $objItem.PageFileUsage & @CRLF $Output &= "ParentProcessId: " & $objItem.ParentProcessId & @CRLF $Output &= "PeakPageFileUsage: " & $objItem.PeakPageFileUsage & @CRLF $Output &= "PeakVirtualSize: " & $objItem.PeakVirtualSize & @CRLF $Output &= "PeakWorkingSetSize: " & $objItem.PeakWorkingSetSize & @CRLF $Output &= "Priority: " & $objItem.Priority & @CRLF $Output &= "PrivatePageCount: " & $objItem.PrivatePageCount & @CRLF $Output &= "ProcessId: " & $objItem.ProcessId & @CRLF $Output &= "QuotaNonPagedPoolUsage: " & $objItem.QuotaNonPagedPoolUsage & @CRLF $Output &= "QuotaPagedPoolUsage: " & $objItem.QuotaPagedPoolUsage & @CRLF $Output &= "QuotaPeakNonPagedPoolUsage: " & $objItem.QuotaPeakNonPagedPoolUsage & @CRLF $Output &= "QuotaPeakPagedPoolUsage: " & $objItem.QuotaPeakPagedPoolUsage & @CRLF $Output &= "ReadOperationCount: " & $objItem.ReadOperationCount & @CRLF $Output &= "ReadTransferCount: " & $objItem.ReadTransferCount & @CRLF $Output &= "SessionId: " & $objItem.SessionId & @CRLF $Output &= "Status: " & $objItem.Status & @CRLF $Output &= "TerminationDate: " & WMIDateStringToDate($objItem.TerminationDate) & @CRLF $Output &= "ThreadCount: " & $objItem.ThreadCount & @CRLF $Output &= "UserModeTime: " & $objItem.UserModeTime & @CRLF $Output &= "VirtualSize: " & $objItem.VirtualSize & @CRLF $Output &= "WindowsVersion: " & $objItem.WindowsVersion & @CRLF $Output &= "WorkingSetSize: " & $objItem.WorkingSetSize & @CRLF $Output &= "WriteOperationCount: " & $objItem.WriteOperationCount & @CRLF $Output &= "WriteTransferCount: " & $objItem.WriteTransferCount & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Process" ) Endif Func WMIDateStringToDate($dtmDate) If $dtmDate = "" Then Return "" Local $wDay, $wMth, $wYr, $wHr, $wMin, $wSec, $nDate $wDay = StringMid($dtmDate, 5, 2) & "/" $wMth = StringMid($dtmDate, 7, 2) & "/" $wYr = StringLeft($dtmDate, 4) & " " $wHr = StringMid($dtmDate, 9, 2)& ":" $wMin = StringMid($dtmDate, 11, 2) & ":" $wSec = StringMid($dtmDate,13, 2) $nDate = $wDay & $wMth & $wYr & $wHr & $wMin & $wSec Return $nDate EndFunc George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 23, 2009 Share Posted June 23, 2009 Some of the process attributes are time-based and will always return 0 unless queried with a wbemRefresher. Look at the code for _ProcessListProperties() for an example of how to do this. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
AoRaToS Posted June 23, 2009 Share Posted June 23, 2009 "Rum Command, Rum Command"I hope you're not trying to RUM a command, that's not possible, try run-ning it for better results...Is that a Windows PowerShell script you're using? s!mpL3 LAN Messenger Current version 2.9.9.1 [04/07/2019] s!mpL3 LAN Messenger.zip s!mpL3 Link to comment Share on other sites More sharing options...
weaponx Posted June 23, 2009 Share Posted June 23, 2009 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