Jump to content
Sign in to follow this  
GAM

Rum Command

Recommended Posts

GAM

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

Share this post


Link to post
Share on other sites
Juvigy

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')

Share this post


Link to post
Share on other sites
GodlessSinner

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 by Vitas

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
GAM

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

Share this post


Link to post
Share on other sites
99ojo

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?

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

Share this post


Link to post
Share on other sites
spudw2k

There are numerous scripts on this forum that show how to perform WMI queries...which is all that the powershell script is doing.

Share this post


Link to post
Share on other sites
Ascend4nt

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?

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 :D

Share this post


Link to post
Share on other sites
GodlessSinner

Can you please let me know if I can get the above counters using AUTOIT?

ok.

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
GEOSoft

$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!"

Share this post


Link to post
Share on other sites
PsaltyDS

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.

:D


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

Share this post


Link to post
Share on other sites
AoRaToS

"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.8.8 [30/09/2015]

Download Here

s!mpL3

Share this post


Link to post
Share on other sites
weaponx
Posted Image

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.