netmaple 发表于 2010-6-28 17:14:32

按目录结束 如何排除个别文件不被同时结束

本帖最后由 netmaple 于 2010-6-28 17:25 编辑

$list = ProcessList()
for $i = 1 to $list
If StringInStr(Procespath($list[$i]), "C:\Program Files\wx\") > 1 Then
ProcessClose($list[$i])
If ProcessExists($list[$i]) Then RunWait(@SystemDir&"\ntsd.exe -c q -p "&$list[$i],"",@SW_HIDE)
;If ProcessExists($list[$i]) Then .....
endif
next

Func Procespath($pid)
$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = "&$pid)

For $objItem In $colItems

$cmdpath = $objItem.CommandLine
$exepath = $objItem.ExecutablePath
$path=StringSplit($cmdpath,"\")

if $path<=2 Then
Return $exepath
Else
Return $cmdpath
EndIf

Next
EndFunc
备注这样会结束所有"wx"目录下的进程,我想保留其中3个进程
比如进程名字:wx1.exe xw.exe msg.exe

请高手指点

afan 发表于 2010-6-28 17:48:44

$list = ProcessList()
For $i = 1 To $list
        If StringRegExp($list[$i], '^(wx1\.exe|xw\.exe|msg\.exe)$') Then ContinueLoop
        If StringInStr(Procespath($list[$i]), "C:\Program Files\wx\") > 1 Then
                ProcessClose($list[$i])
                If ProcessExists($list[$i]) Then RunWait(@SystemDir & "\ntsd.exe -c q -p " & $list[$i], "", 0)
        EndIf
Next

Func Procespath($pid)
        $strComputer = "."
        $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
        $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessId = " & $pid)
        For $objItem In $colItems
                $cmdpath = $objItem.CommandLine
                $exepath = $objItem.ExecutablePath
                $path = StringSplit($cmdpath, "\")
                If $path <= 2 Then Return $exepath
                Return $cmdpath
        Next
EndFunc   ;==>Procespath

masterpcc 发表于 2010-6-28 20:26:17

新手!!努力学习中!!
页: [1]
查看完整版本: 按目录结束 如何排除个别文件不被同时结束