Showing posts with the label Kill a program in VBScript

Some tricks and codes in VBScript

'Sample VBScript to kill a program Option Explicit Dim objWMIService, objProcess, colProcess Dim strComputer, strProcessKill strComputer = "." strProcessKill = "'application.exe'" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colProcess = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = " & strProcessKill ) For Each objProcess in colProcess objProcess.Terminate() Next WScript.Quit ' End of WMI Example of a Kill Process 'Sample VBScript to create a file Dim oAPI, oBag Set oAPI = CreateObject(“MOM.ScriptAPI”) Set oBag = oAPI.CreatePropertyBag() Set objFSO = CreateObject(“Scripting.FileSystemObject”) strFile = “C:\myfile.log” If objFSO.FileExists(strFile) Then Call oBag.AddValue(“Status”,”Ok”) Call oAPI.Return(oBag) Else Call oBag.AddValue(“Status”,”Error”) Call oAPI.Retu