如何使用Vb脚本终止VBS文件..我尝试了这段代码但它无法正常工作,
Call StopProcessVBS(strComputer,strProcess)
Function StopProcessVBS (strComputerArg,strProcessArg)
Set WshShell = CreateObject("WScript.Shell")
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputerArg & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'cscript.exe' OR Name = 'wscript.exe'")
For Each objItem in colItems
If objItem.CommandLine = strProcessArg Then
**objItem.CommandLine.Terminate()**
End If
Next
Set WshShell = Nothing
Set objWMIService = Nothing
Set colItems = Nothing
End Function
答案 0 :(得分:1)
最后工作,尝试下面的代码
strComputer = "."
Call StopProcessVBS(strComputer,strProcess)
Function StopProcessVBS (strComputerArg,strProcessArg)
Set WshShell = CreateObject("WScript.Shell")
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputerArg & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_Process Where Name = 'cscript.exe' OR Name = 'wscript.exe'")
For Each objItem in colItems
If Instr (1,Replace(objItem.CommandLine,"""",""),strProcessArg) Then
objItem.Terminate()
End If
Next
Set WshShell = Nothing
Set objWMIService = Nothing
Set colItems = Nothing
End Function