116154801 发表于 2009-3-6 02:00:51

查看D盘正在运行的程序

怎么样才能知道进程里面 谁谁谁 才是属于D盘运行的程序 然后结束掉它, 拜托各位大侠能帮帮小弟,小弟先谢谢各位了

[ 本帖最后由 116154801 于 2009-4-14 13:24 编辑 ]

sxd 发表于 2009-3-6 06:29:10

这个udf可以
;===============================================================================
; Function Name:    _ProcessListProperties()
; Description:   Get various properties of a process, or all processes
; Call With:       _ProcessListProperties( [$Process [, $sComputer]] )
; Parameter(s):   (optional) $Process - PID or name of a process, default is "" (all)
;         (optional) $sComputer - remote computer to get list from, default is local
; Requirement(s):   AutoIt v3.2.4.9+
; Return Value(s):On Success - Returns a 2D array of processes, as in ProcessList()
;             with additional columns added:
;             - Number of processes listed (can be 0 if no matches found)
;             - 1st process name
;             - 1st process PID
;             - 1st process Parent PID
;             - 1st process owner
;             - 1st process priority (0 = low, 31 = high)
;             - 1st process executable path
;             - 1st process CPU usage
;             - 1st process memory usage
;             - 1st process creation date/time = "MM/DD/YYY hh:mm:ss" (hh = 00 to 23)
;             - 1st process command line string
;             ...
;             thru - last process properties
; On Failure:       Returns array with = 0 and sets @Error to non-zero (see code below)
; Author(s):      PsaltyDS at http://www.autoitscript.com/forum
; Date/Version:   09/17/2008--v2.0.3
; Notes:            If an integer PID or string process name is provided and no match is found,
;             then = 0 and @error = 0 (not treated as an error, same as ProcessList)
;         This function requires admin permissions to the target computer.
;         All properties come from the Win32_Process class in WMI.
;             To get time-base properties (CPU and Memory usage), a 100ms SWbemRefresher is used.
;===============================================================================
Func _ProcessListProperties($Process = "", $sComputer = ".")
    Local $sUserName, $sMsg, $sUserDomain, $avProcs, $dtmDate
    Local $avProcs = [], $n = 1

    ; Convert PID if passed as string
    If StringIsInt($Process) Then $Process = Int($Process)

    ; Connect to WMI and get process objects
    $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\" & $sComputer & "\root\cimv2")
    If IsObj($oWMI) Then
      ; Get collection processes from Win32_Process
      If $Process = "" Then
            ; Get all
            $colProcs = $oWMI.ExecQuery("select * from win32_process")
      ElseIf IsInt($Process) Then
            ; Get by PID
            $colProcs = $oWMI.ExecQuery("select * from win32_process where ProcessId = " & $Process)
      Else
            ; Get by Name
            $colProcs = $oWMI.ExecQuery("select * from win32_process where Name = '" & $Process & "'")
      EndIf

      If IsObj($colProcs) Then
            ; Return for no matches
            If $colProcs.count = 0 Then Return $avProcs

            ; Size the array
            ReDim $avProcs[$colProcs.count + 1]
            $avProcs = UBound($avProcs) - 1

            ; For each process...
            For $oProc In $colProcs
                ; = Process name
                $avProcs[$n] = $oProc.name
                ; = Process PID
                $avProcs[$n] = $oProc.ProcessId
                ; = Parent PID
                $avProcs[$n] = $oProc.ParentProcessId
                ; = Owner
                If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n] = $sUserDomain & "\" & $sUserName
                ; = Priority
                $avProcs[$n] = $oProc.Priority
                ; = Executable path
                $avProcs[$n] = $oProc.ExecutablePath
                ; = Creation date/time
                $dtmDate = $oProc.CreationDate
                If $dtmDate <> "" Then
                  ; Back referencing RegExp pattern from weaponx
                  Local $sRegExpPatt = "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)"
                  $dtmDate = StringRegExpReplace($dtmDate, $sRegExpPatt, "$2/$3/$1 $4:$5:$6")
                EndIf
                $avProcs[$n] = $dtmDate
                ; = Command line string
                $avProcs[$n] = $oProc.CommandLine

                ; increment index
                $n += 1
            Next
      Else
            SetError(2); Error getting process collection from WMI
      EndIf
      ; release the collection object
      $colProcs = 0

      ; Get collection of all processes from Win32_PerfFormattedData_PerfProc_Process
      ; Have to use an SWbemRefresher to pull the collection, or all Perf data will be zeros
      Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher")
      $colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet
      $oRefresher.Refresh

      ; Time delay before calling refresher
      Local $iTime = TimerInit()
      Do
            Sleep(20)
      Until TimerDiff($iTime) >= 100
      $oRefresher.Refresh

      ; Get PerfProc data
      For $oProc In $colProcs
            ; Find it in the array
            For $n = 1 To $avProcs
                If $avProcs[$n] = $oProc.IDProcess Then
                  ; = CPU usage
                  $avProcs[$n] = $oProc.PercentProcessorTime
                  ; = memory usage
                  $avProcs[$n] = $oProc.WorkingSet
                  ExitLoop
                EndIf
            Next
      Next
    Else
      SetError(1); Error connecting to WMI
    EndIf

    ; Return array
    Return $avProcs
EndFunc;==>_ProcessListProperties

116154801 发表于 2009-3-11 02:49:59

怎么用呢?

xayle 发表于 2009-3-11 03:13:31

;             - 1st process executable path
这个获取执行路径
;             - 1st process command line string
这个可以获取参数

sxd 发表于 2009-3-11 10:38:13

在此强烈呼吁下次注释默认的不是斜体每次安装版本我都改了

注释斜体后 让人感觉都不太想去看注释了

116154801 发表于 2009-3-13 02:59:21

哎,我会英文就好了。。。

298311657 发表于 2009-3-15 12:53:42

如此?

$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2:win32_process")
$colItems = $objWMIService.instances_
For $objItem In $colItems
        $pid = $objItem.ProcessId
        $name = $objItem.Name
        $path = $objItem.executablepath
        $ce=StringMid ( $path, 1 , 3 )
        If $ce = 'D:\' Then
                FileWriteLine('123.txt','进程名:'&$name&'路径:'&$path)
        EndIf
Next

xrbenbeba 发表于 2009-3-15 20:36:00

原帖由 298311657 于 2009-3-15 12:53 发表 http://www.autoitx.com/images/common/back.gif
如此?

$objWMIService = ObjGet("winmgmts:\\.\root\CIMV2:win32_process")
$colItems = $objWMIService.instances_
For $objItem In $colItems
        $pid = $objItem.ProcessId
        $name = $objItem.Name
       ...


支持WMI的写法

mcknight1013 发表于 2009-3-16 03:15:10

好强!!学习了!

116154801 发表于 2009-4-14 13:21:54

高手就是不一样~!强~!

a757248228 发表于 2009-4-17 17:22:46

不是很懂:face (24):
页: [1]
查看完整版本: 查看D盘正在运行的程序