我有多個用戶在Windows 2003服務器上運行attachemate。我想殺死user_1啓動的attachemate.exe,而不會殺死user_2啓動的attachemate.exe。我怎樣才能殺死一個進程,使用VBScript,由特定用戶啓動
我想使用VBScript。
我有多個用戶在Windows 2003服務器上運行attachemate。我想殺死user_1啓動的attachemate.exe,而不會殺死user_2啓動的attachemate.exe。我怎樣才能殺死一個進程,使用VBScript,由特定用戶啓動
我想使用VBScript。
一旦你有,你可以使用Win32_Process的到你可以使用它來找出流程所有者是誰,然後通過進程ID來終止進程。
MSDN Win32_Process class details
MSDN Terminating a process with Win32_Process
有肯定是一個更清潔的方式來做到這一點,但這裏是我想出了。注:這並不涉及多個相同名稱的進程當然,但我想你可以用數組來處理這部分來保存它們或類似的東西。 :)
strComputer = "."
strOwner = "A111111"
strProcess = "'notepad.exe'"
' Connect to WMI service and Win32_Process filtering by name'
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcessbyName = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " _
& strProcess)
' Get the process ID for the process started by the user in question'
For Each objProcess in colProcessbyName
colProperties = objProcess.GetOwner(strUsername,strUserDomain)
if strUsername = strOwner then
strProcessID = objProcess.ProcessId
end if
next
' We have the process ID for the app in question for the user, now we kill it'
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" & strProcessID)
For Each objProcess in colProcess
objProcess.Terminate()
Next
命令行pskill:pskill -u USER_1 attachemate.exe
需要安裝pskill並不理想。我更喜歡一個不需要我安裝任何新東西的解決方案。 – GlennH 2008-09-16 20:07:27