0

I tried to do it this way:

Dim objFSO, outFile, wshShell
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set outFile = objFSO.CreateTextFile("paint.bat", True)
outFile.WriteLine "taskkill /f /im mspaint.exe"
Set wshShell = CreateObject("WScript.Shell")
wshShell.Run "paint.bat", 0, false

that was to work but of an error saying "The file is already being used by another process"

2 Answers 2

1

The file is already being used by your own cscript or wscript process. You should use outFile.Close (and maybe moreover Set outFile = Nothing) before run.

Sign up to request clarification or add additional context in comments.

Comments

0

Terminates paint directly in vbscript.

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_Process")
For Each objItem in colItems
    If objitem.Name = "mspaint.exe" Then
        msgbox objitem.name & " PID=" & objItem.ProcessID & " SessionID=" & objitem.sessionid
        objitem.terminate
    End If
Next

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.