用vbs关闭hta文件不起作用?

时间:2014-05-09 09:09:13

标签: vbscript hta taskkill

我试图用vbs关闭一个* .hta文件,但我无法让它关闭我认为以下是正确的方法吗?

    Set ws=CreateObject("WScript.Shell")
ws.Run "TASKKILL.exe /F /IM 1846.hta"

2 个答案:

答案 0 :(得分:2)

正在运行的.hta的映像名称是mshta.exe,因为该程序托管了该脚本。如果有多个.hta在运行,你必须考虑确定所需的过程。

答案 1 :(得分:1)

也许这样做:

Option Explicit
Call FindProcessbyName("1846.hta")
'**********************************************************************************************
Sub FindProcessbyName(FileName)
    On Error Resume Next
    Dim WshShell,strComputer,objWMIService,colProcesses,objProcess
    Set WshShell = CreateObject("Wscript.Shell")
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
    For Each objProcess in colProcesses
        If InStr(objProcess.CommandLine,FileName) > 0 Then
            If Err <> 0 Then
                MsgBox Err.Description,VbCritical,Err.Description
            Else
                objProcess.Terminate(0) 
            End if
        End If
    Next
End Sub
'**********************************************************************************************