简体   繁体   中英

“Permission Denied” error when using WScript.Shell.Logevent

My environment is Classic ASP. I want to log an event to the Event Log (doesn't really matter which one). I have built a quick test (code below) and keep getting "Permission Denied".

const SUCCESS = 0
const ERROR = 1
const WARNING = 2
const INFORMATION = 4
const AUDIT_SUCCESS = 8
const AUDIT_FAILURE = 16

dim WshShell
set WshShell = Server.CreateObject("WScript.Shell")
wshshell.Logevent WARNING, "Test Event Log by Windows Script Host!"
set wshshell=nothing
Response.write "Event Logged Successfully by Windows Script Host!"

I searched online for a solution to this problem and found some sort of answer. Unfortunately, their solution doesn't work. They say:

Set the following Registry key to 0 instead of 1, and then restart your computer for the changes to take effect. HKLM\\System\\CurrentControlSet\\Services\\EventLog\\Application Name: RestrictGuestAccess Type: REG_DWORD NOTE: This enables all Guest accounts to write to the Application Event Log.

Is there a better way to do this? Or a real solution, for that matter?

Essentially, I'm trying to log critical errors to some Windows Event Log which will allow for a monitoring system to consume them.

My OS is Windows Server 2003 which uses IIS 6.0.

The actual code will be running on Windows Server 2008 R2 with IIS 7.5.

Does the OS or even the IIS Web Server matter?

Don't bother using Classic ASP and COM objects to do the deed. Rather, build a SQL Stored Procedure (2005 or later) and log to the event log with xp_logevent.

You can see how to do this at http://msdn.microsoft.com/en-us/library/ms186244.aspx

Once I implemented this approach, everything worked and I walked away after 20 minutes of coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM