我正在尝试使用VB脚本在用户的计算机上关闭打开的OneNote应用程序。但是,我似乎无法让它发挥作用。在运行剩余的VBS文件之前,我需要关闭任何打开的OneNotes。到目前为止,我已尝试过这个,但不适用于OneNote。
Set oNote= CreateObject("WScript.Shell")
oNote.Exec "onenote"
oNote.Terminate
这是我尝试过的另一个代码。都没有工作。
Set oNote= CreateObject("onenote")
oNote.Quit
答案 0 :(得分:1)
您可以尝试以这种方式杀死Onenote.exe
进程
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
'****************************************************
或通过这种方式:
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