gpt4 book ai didi

Outlook 启动和关闭事件 ID

转载 作者:行者123 更新时间:2023-12-04 04:43:37 25 4
gpt4 key购买 nike

我正在编写一个批处理脚本,以便在 Outlook 关闭时备份我的 pst 文件。

我正在考虑根据 Windows 事件 ID 执行计划任务。

我搜索了 Microsoft Outlook 的各种事件 ID,但无法获得所需的。

我尝试分析 eventvwr 但无法找到所需的。

我正在使用 Windows 7 Professional 64 位 Outlook 2010。我正在寻找 Outlook 的开始和停止事件 ID

最佳答案

因此,正如我之前所说,据我所知,Outlook 启动/关闭没有事件,如果您安装了插件,您可以使用 ID:45 来检测启动,但您仍然没有关闭事件!

在 Outlook 启动/关闭事件中获取事件的唯一方法是通过 Outlook 插件或在 Outlook 启动和退出事件上执行的 VBA-Makro 自行制作。

Outlook 插件示例:

public partial class ThisAddIn
{
private EventLog log = null;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
log = new EventLog();
log.Source = "OutlookAddIn";
log.Log = "Application";
log.WriteEntry("Outlook start", EventLogEntryType.Information, 1);
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
if (log != null)
{
log.WriteEntry("Outlook stop", EventLogEntryType.Information, 0);
}
}

#region VSTO generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}

#endregion
}

更新

我自己尝试过 VBA 解决方案,它奏效了 ;-)

使用以下代码 ( Source) 创建一个模块

Option Explicit

Declare Function RegisterEventSource Lib "advapi32.dll" Alias _
"RegisterEventSourceA" (ByVal lpUNCServerName As String, _
ByVal lpSourceName As String) As Long
Declare Function DeregisterEventSource Lib "advapi32.dll" ( _
ByVal hEventLog As Long) As Long
Declare Function ReportEvent Lib "advapi32.dll" Alias _
"ReportEventA" ( _
ByVal hEventLog As Long, ByVal wType As Integer, _
ByVal wCategory As Integer, ByVal dwEventID As Long, _
ByVal lpUserSid As Any, ByVal wNumStrings As Integer, _
ByVal dwDataSize As Long, plpStrings As Long, _
lpRawData As Any) As Boolean
Declare Function GetLastError Lib "kernel32" () As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
hpvDest As Any, hpvSource As Any, _
ByVal cbCopy As Long)
Declare Function GlobalAlloc Lib "kernel32" ( _
ByVal wFlags As Long, _
ByVal dwBytes As Long) As Long
Declare Function GlobalFree Lib "kernel32" ( _
ByVal hMem As Long) As Long

Public Const EVENTLOG_SUCCESS = 0
Public Const EVENTLOG_ERROR_TYPE = 1
Public Const EVENTLOG_WARNING_TYPE = 2
Public Const EVENTLOG_INFORMATION_TYPE = 4
Public Const EVENTLOG_AUDIT_SUCCESS = 8
Public Const EVENTLOG_AUDIT_FAILURE = 10

Public Sub LogNTEvent(sString As String, iLogType As Integer, _
iEventID As Long)
Dim bRC As Boolean
Dim iNumStrings As Integer
Dim hEventLog As Long
Dim hMsgs As Long
Dim cbStringSize As Long
hEventLog = RegisterEventSource("", Application.Name)
cbStringSize = Len(sString) + 1
hMsgs = GlobalAlloc(&H40, cbStringSize)
CopyMemory ByVal hMsgs, ByVal sString, cbStringSize
iNumStrings = 1
If ReportEvent(hEventLog, _
iLogType, 0, _
iEventID, 0&, _
iNumStrings, cbStringSize, _
hMsgs, hMsgs) = 0 Then
MsgBox GetLastError()
End If
Call GlobalFree(hMsgs)
DeregisterEventSource (hEventLog)
End Sub

这就是您的 OutlookSessionApplication 文件的外观 ( how to get there) 并且不要忘记允许 makros 或在您编写的文件上签名 ;-)

   Private Sub Application_Quit()
Call LogNTEvent("OUTLOOK QUIT", _
EVENTLOG_INFORMATION_TYPE, 1000)
End Sub

Private Sub Application_Startup()
Call LogNTEvent("OUTLOOK START", _
EVENTLOG_INFORMATION_TYPE, 1001)
End Sub

关于Outlook 启动和关闭事件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18535873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com