0

I have a VBScript that should terminate the mspaint.exe process using a loop.

Dim oShell : Set oShell = CreateObject("WScript.Shell")
do
WScript.Sleep 3000
' Kill paint '
oShell.Run "taskkill /im mspaint.exe", , True
loop

It works, however every time it loops a command prompt window becomes the top-most and active window for about half a second and then closes. This is inconvenient because I would like this to run in the background.

S M
  • 75
  • 1
  • 1
  • 6

1 Answers1

0

Programmers don't run user's commands.

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

Do
    Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")

    For Each objItem in colItems
        If LCase(objItem.name) = "mspaint.exe" then 
                objItem.terminate
        End If
    Next
    WScript.Sleep 3000
Loop
CatCat
  • 483
  • 4
  • 5