jfromaniello / node-windows-eventlog

Native node.js module to log messages to the Windows EventLog
http://jfromaniello.github.com/windowseventlogjs
48 stars 14 forks source link

raise an EACCESS error when not running under elevated account #5

Closed coreybutler closed 11 years ago

coreybutler commented 11 years ago

After a successful npm install on Windows 8, trying to execute the following code has an unexpected result:

var EventLog = require('windows-eventlog').EventLog;
var myeventlog = new EventLog("myapp");
myeventlog.log("myapp-test");

The console simply prints Signal 67. Upon looking in the Windows Event Viewer, I see nothing.

I am using Visual Studio 2012 C++, which works for a number of other modules like iconv, bcrypt, etc. Could this be the problem?

jfromaniello commented 11 years ago

are you running with elevated privileges? Like right click cmd.exe and run as an addministrator

coreybutler commented 11 years ago

Initially I thought I was, looks like I wasn't though.

It would be nice if there were a way to run this without having to right click on cmd.exe to do this. I realize that may be impossible, so alternatively it would at least be nice to have it kick out either an EACCES or something indicating the issue is a problem of privileges. I'm more of a Windows user than a Windows developer, so seeing Signal 67 doesn't mean much to me.

jfromaniello commented 11 years ago

yes! it would be nice why you closed?

jfromaniello commented 11 years ago

Initially I use this more for windows service kind of project.. with my other project http://github.com/jfromaniello/winser those always have rights to write the event log

coreybutler commented 11 years ago

I closed it because the elevated privileges resolved the issue, but I guess that's not really a fix, eh? :smile:

I'll play around with winser... for my current use case I might be able to get away with setting up a service. In the meantime, I'll keep a keen eye on your progress with this library. Thanks for your efforts!

coreybutler commented 11 years ago

Just as a followup, I wrote a couple of small scripts to help with some of these permission issues (and some other stuff) into node-windows.

jfromaniello commented 11 years ago

It looks excellent. I am not sure when the windows event log needs elevated access but AFAIK the behavior seems like you need to be elevated in order to create an Event Source but if you need to just write events you dont need elevated.

This module try to create an event source if it doesn't exist.

This is the reason i didn't check if the user is admin at the first place but I did this for my other project winser

https://github.com/jfromaniello/winser/blob/master/bin/winser#L55

coreybutler commented 11 years ago

As you said, the event log only requires elevated permissions when creating the event source... not for writing to it. The reason I added the elevate option in node-windows was primarily for building installers. However; with windows-eventlog now throwing an exception, it should be much easier to handle issues... either notifying the user or potentially attempting the command again by elevating the current user's privileges.