-1

Im trying to close a *.hta file ussing vbs but i cant get it to close I thoght the following would be the right way about ?

    Set ws=CreateObject("WScript.Shell")
ws.Run "TASKKILL.exe /F /IM 1846.hta"
LabRat
  • 1,996
  • 11
  • 56
  • 91
  • Please check this [answer](http://stackoverflow.com/a/14080525/1169519). It's not a complete answer to your question, but maybe you get some ideas. – Teemu May 09 '14 at 10:12

2 Answers2

2

The image name of a running .hta is mshta.exe, because this program host the script. You'll have to think about identifying the desired process if there are more than one .hta running.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
1

Perhaps doing something like that :

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
'**********************************************************************************************
Hackoo
  • 18,337
  • 3
  • 40
  • 70