Fly Guy
Fly Guy

Reputation: 265

Close an open OneNote application using VBS

I'm trying to close an open OneNote application on a user's computer using VB Script. However, I cannot seem to get it to work. I need to close any open OneNotes before I run the rest of the VBS file. So far I've tried this, but doesn't work for OneNote.

Set oNote= CreateObject("WScript.Shell")
oNote.Exec "onenote"
oNote.Terminate

This is another code I've tried. Neither work.

Set oNote= CreateObject("onenote")
oNote.Quit

Upvotes: 0

Views: 914

Answers (1)

Hackoo
Hackoo

Reputation: 18837

You can try like this way to kill Onenote.exe process

Option Explicit
Dim Process
Process = "Onenote.exe"
Call Kill(Process)
'****************************************************
Sub Kill(Process)
    Dim Ws,Command,Execution
    Set Ws = CreateObject("Wscript.Shell")
    Command = "cmd /c Taskkill /F /IM "& Process &""
    Execution = Ws.Run(Command,0,True)
    Set Ws = Nothing
End Sub 
'****************************************************

Or by this way :

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strComputer = "."
strProcessKill = "'Onenote.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(1)
Next 

Upvotes: 1

Related Questions