关闭除系统进程外进程问题
写了个简单的程序,发现并没有用。。求达人帮忙更改。。#NoTrayIcon#Include <Array.au3>
$Processlist=ProcessList()
Dim $sysProlist=["system", "smss.exe","csrss.exe","lsass.exe","svchost.exe", "winlogon.exe","iexplore.exe","services.exe","System Idle Process","explorer.exe","internat.exe", "taskmgr.exe"]
For $i=1 To $Processlist
$a=_ArrayBinarySearch($sysProlist,$Processlist[$i])
If @error=3 Then ProcessClose($Processlist[$i])
Next
#NoTrayIcon
#Include <Array.au3>
$Processlist=ProcessList()
Dim $sysProlist=["system", "smss.exe","csrss.exe","lsass.exe","svchost.exe", "winlogon.exe","iexplore.exe","services.exe","System Idle Process","explorer.exe","internat.exe","QQ.exe","client.exe"]
Dim $err[$Processlist]
For $i=1 To $Processlist
$tmp=0
For $b=0 To 13
If $Processlist[$i]=$sysProlist[$b] Then $tmp=1
Next
If $tmp=0 Then ProcessClose($Processlist[$i])
Next
我用上面方法解决了,但我还是想知道为什么 刚才那样不行
我试了每个进程的@error全是2 本帖最后由 afan 于 2010-8-3 00:24 编辑
_ArrayBinarySearch 必须先排序
用_ArraySearch即可 可以用简单的方法#NoTrayIcon
$Processlist = ProcessList()
$sysProlist = ';system;smss.exe;csrss.exe;lsass.exe;svchost.exe;winlogon.exe;iexplore.exe;services.exe;System Idle Process;explorer.exe;internat.exe;taskmgr.exe;'
For $i = 1 To $Processlist
If Not StringInStr($sysProlist, ';' & $Processlist[$i] & ';') Then MsgBox(0, $Processlist[$i], $Processlist[$i])
Next 本帖最后由 netegg 于 2010-8-3 12:00 编辑
#include <array.au3>
#include <security.au3>
$tag_WTS_PROCESS_INFO= _
"DWORD SessionId;" & _
"DWORD ProcessId;" & _
"PTR pProcessName;" & _
"PTR pUserSid"
; ############ Example code #######################
MsgBox(0,"Process by name or number(PID)", "Explorer.exe------" & _ProcessListOWNER_WTS("Explorer.exe"))
$temp=_ProcessListOWNER_WTS()
$temp="Process"
$temp="ProcessId"
$temp="SessionId"
$temp="ProcessOWNER"
_ArrayDisplay($temp, "Process list with OWNER...")
; ###############################################
; ############ Here be func! ####################
Func _ProcessListOWNER_WTS($PID=0)
Local $i, $ret, $ret1, $mem
$ret=DllCall("WTSApi32.dll", "int", "WTSEnumerateProcesses", "int", 0, "int", 0, "int", 1, "ptr*", 0, "int*", 0)
Local $array[$ret]
$mem=DllStructCreate($tag_WTS_PROCESS_INFO,$ret)
for $i=0 to $ret-1
$mem=DllStructCreate($tag_WTS_PROCESS_INFO, $ret+($i*DllStructGetSize($mem)))
;if DllStructGetData($mem, "pProcessName") Then
$string=DllStructCreate("char", DllStructGetData($mem, "pProcessName"))
$array[$i]=DllStructGetData($string,1)
;EndIf
$array[$i]=DllStructGetData($mem, "ProcessId")
$array[$i]=DllStructGetData($mem, "SessionId")
;if DllStructGetData($mem, "pUserSid") Then
$ret1 = _Security__LookupAccountSid(DllStructGetData($mem, "pUserSid"))
if IsArray($ret1) Then $array[$i]=$ret1
;EndIf
Next
DllCall("WTSApi32.dll", "int", "WTSFreeMemory", "int", $ret)
if $PID Then
if IsInt($PID) Then
for $i=0 to UBound($array, 1) - 1
if $array[$i] = $PID Then
Return $array[$i]
EndIf
Next
Else
for $i=0 to UBound($array, 1) - 1
if $array[$i] = $PID Then
Return $array[$i]
EndIf
Next
EndIf
EndIf
Return $array
EndFunc
;################################ END FUNC ##########################################
呵呵,学习一下哈。。
页:
[1]