Jump to content

Rum Command


 Share

Recommended Posts

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

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

_____________________________________________________________________________

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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 Builder
Misc 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 Array
Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc
Cool Stuff: AutoItObject UDF â—Š Extract Icon From Proc â—Š GuiCtrlFontRotate â—Š Hex Edit Funcs â—Š Run binary â—Š Service_UDF

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

$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

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...