我希望制作一个简短的javascript代码来杀死我的Windows机器上运行的进程(我正在开发7上的程序,但它必须在服务器2003上生产时运行)。我已经开始使用以下代码:
w = new ActiveXObject("WScript.Shell");
w.run("taskkill.exe /im iexpore.exe");
return true;
我需要制作一个被我杀过的东西。有许多不同的东西可以杀死,我有另一个程序来决定一个人被杀死。
我现在有以下代码,但它仍然无效:
Dim prcid
Dim check
Dim Inp
Set Inp = WScript.Arguments
check=0
Set objService = GetObject("winmgmts:")
For Each Process In objService.InstancesOf("Win32_process")
If process.name= "Inp" Then
prcid=process.processid
check=1
Exit For
End If
Next
If check =0 Then
WScript.Quit [ExitCode]
End if
For Each process In objService.InstancesOf("Win32_process")
If process.name= "Inp" Then
If process.processid=prcid Then
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process WHERE Name = 'Inp'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
End If
Exit For
End If
Next
答案 0 :(得分:0)
我假设您使用的是Windows脚本宿主。
您可以像这样访问脚本的参数:
objArgs = WScript.Arguments;
for (i = 0; i < objArgs.length; i++)
{
WScript.Echo(objArgs(i));
}
我假设您希望将要杀死的进程作为参数传递给脚本。
吨。
答案 1 :(得分:-1)
您已经提到了javascript,但是您的代码是VB脚本,因此应具有.vbs扩展名。可能是您的问题吗?