2010年12月8日 星期三

Vb.Net 寫事件檢視器寫入問題

Vista,Windows7+UAC
WINServer2003 2008 寫事件檢視器寫入問題

Code:

Dim myLog As New Diagnostics.EventLog
Dim dtNow As Date = Date.Now
Dim EventStr As String = "DATE:" & dtNow.ToString & "." & Format(dtNow, "ffff")

' Write an information to the event log.

myLog.Source = "XXXX"
myLog.Log = "Application"
myLog.WriteEntry(EventStr, ErrorType)myLog.Dispose()

是想要在系統事件器的應用程式(Application)中
加一個來源(Source)為XXXX的事件
XP上應該都OK啦,
但是VISTA,WINDOWS7,WINS2003,WINS2008管的比較嚴,就可能會有問題,
如果出現錯誤[System.Security.SecurityException: 不允許要求的登錄權限。],
就必要要做以下的調整

在 [登錄編輯程式(Regedit)] 中建立事件來源(XXX)下
應用程式(Application)事件日誌(EvenlLog)。
1.執行Regedit
2.HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application增加機碼XXX就這樣嘍

MS寫的很複雜,原文如下 http://support.microsoft.com/kb/329291

1 則留言:

Water Shau 提到...

WIN7 在不關閉 UAC 的情況下,
應該是安裝程式要在取得系統管理者權限時,
在 Regedit 插入這些 Reg值
之後被安裝的程式就可以順利的 RUN