windows - 写入 Windows 安全日志

标签 windows security powershell logging

我有一个脚本,当它完成显示运行它的用户时,我需要将审计事件写入 Windows 安全日志。

除了安全日志,我可以写入任何日志。

我该怎么做?

New-EventLog -LogName Security -Source "MyApp"
Write-EventLog -LogName Security -source "MyApp" -EntryType Information -EventId 1 -Message "Script run by X"

当名称从 Security 更改为 Application 或 System 时,它起作用了 - 但是,我在使用 Security 时不断收到以下信息:

Write-EventLog : The registry key for the log "Security" for source "msevent" could not be opened. At line:1 char:1 + Write-EventLog -LogName Security -source "msevent" -EntryType Information -Event ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (:) [Write-EventLog], Exception + FullyQualifiedErrorId : AccessDenied,Microsoft.PowerShell.Commands.WriteEventLogCommand

我是管理员,我不确定为什么会发生这种情况,即使在尝试修改注册表安全权限之后也是如此。

有人知道我该怎么做吗?

最佳答案

MS 文档:

Only the Local Security Authority (Lsass.exe) has write permission for the Security log. No other account can request this privilege. To write an event to the Security log, use the AuthzReportSecurityEvent function.

这里是文档的链接:Event Logging Security

还有一个链接涵盖了从 powershell 访问 Win API,如果您绝对必须使用安全日志,这应该有助于实现:Use PowerShell to Interact with the Windows API: Part 1

很抱歉不能提供完整的示例,但由于时间限制,现在必须这样做。

问候

关于windows - 写入 Windows 安全日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26611265/

相关文章:

php - 如何从脚本中查找和清理 wordpress,这些脚本会更改您在 Google 和 Yahoo 上的博客帖子标题并带有令人尴尬的 "Viagra text"?

powershell - 将整数 x.xxxxx 格式化为 xx.xxx

powershell - 如何在powershell中移动文件夹及其内容

java - 如何使用java查找正在运行的应用程序处于最小化状态?

php - 如何从 Web 浏览器隐藏 SQL 查询 (PHP)

windows - 如何在 64b 操作系统上执行 Xperf 调用堆栈捕获?

.NET 3.5 安全问题

电源外壳 7 : using ampersand (&) in string literals

Windows 7 应用程序问题 - 仅出现在任务栏中

windows - 如何调试 Jenkins 错误消息 "could not find a suitable ssh-agent provider"?