杀死进程,启动进程

时间:2013-09-23 14:38:32

标签: vbscript process kill

我正在寻找一个VBScript,当用户点击它时,它会检查用户是否正在运行进程winver.exe。如果进程winver.exe在该用户下运行,它将结束该进程,如果进程winver.exe未运行,则将继续使用下面的脚本。

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell")
const iHideWindow = 0

objShell.Run """C:\Program Files (x86)\Citrix\ICA Client\wfcrun32.exe"" ""C:\APP.ica"""

Set oShell = CreateObject("WScript.Shell")
oShell.Run "winver", 0 

1 个答案:

答案 0 :(得分:0)

WMI可能是处理此问题的最佳方式:

Set net = CreateObject("WScript.Network")
user   = LCase(net.UserName)
domain = LCase(net.UserDomain)

Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_Process WHERE Name='winver.exe'"
For Each p In wmi.ExecQuery(qry)
  p.GetOwner u, d
  If LCase(u) = user And LCase(d) = domain Then p.Terminate
Next