Windows Server 2008 不允许我创建日志源,告诉我它已经存在(它不存在)
我有一个小型 winforms 应用程序,可以创建新的事件日志源。
我以管理员身份运行它以获得提升的权限。
该代码检查以确保指定的事件日志不存在,然后创建源。这在我的 Windows 7 计算机上运行良好,但是当我在 Windows Server 2008 R2 SP1 上运行该应用程序时,它告诉我源已经存在。我知道事实并非如此,因为 a) 这是全新安装的 Windows Server 2008 R2,b) 我添加了代码来返回所有日志源的列表,而我的新日志源不在列表中。
我知道“前 8 个字符”是重要的,并且我确保我的源名称是完全唯一的。
这是超级简单的代码(当然我对此进行了尝试/捕获):
if (!EventLog.SourceExists(sourceName))
{
EventLog.CreateEventSource(sourceName, logName);
}
谁能告诉我为什么 Windows Server 2008 对我撒谎?
I have a small winforms app that creates a new event log source.
I run it as administrator for the elevated privileges.
The code checks to ensure the specified event log does not exist and then creates the source. This worked fine on my Windows 7 machine, but when I run the app on Windows Server 2008 R2 SP1 it tells me the source already exists. I know it doesn't because a) this is a fresh installed of Windows Server 2008 R2, and b) I added code to return a list of all the log sources and my new one was not in the list.
I know about the "first 8 characters" being the significant ones and I made sure my source names was completely unique.
Here's the super-easy code (of course I have try/catches around this):
if (!EventLog.SourceExists(sourceName))
{
EventLog.CreateEventSource(sourceName, logName);
}
Can anyone tell me why Windows Server 2008 is lying to me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
本地(或域)管理员不是 Windows 机器上最强大的帐户。
还有其他帐户具有更高(但也更有限)的访问权限。
如果
SourceExists()
退出,但您没有访问权限来了解它,它将返回 false,并且管理员完全有可能被拒绝访问某些内容。此外,对于奇怪地方的事物也有一些保留名称,这些名称可能会让您陷入困境。创建名称为 CON COM 或 LPT 的文件夹通常会在服务器 2003 上引起奇怪的问题。
因此,CreateEventSource() 失败的原因也有很多 - 还要深入研究内部异常,通常这些异常会提供关键细节。
哪个事件日志源名称对您来说失败了?
你能发布异常堆栈吗?
Local (or domain) administrators are not the most powerful accounts on a Windows box.
There are other accounts that have higher (though also more limited) access.
SourceExists()
will return false if it exits but you don't have access rights to know about it, and it's perfectly possible for an administrator to be denied access to something.Also, there are reserved names for things in odd places that can trip you up. Creating folders with the names CON COM or LPT used to cause odd issues on server 2003.
So there also are a whole bunch of reasons why CreateEventSource() can fail - dig into the inner exception(s) as well, often those provide critical detail.
Which event log source name was failing for you?
Would you post the exception stack?