[英]Powershell get Username in gpedit Script
I'm using the gpedit.msc Scripts for Login/Logout/Shutdown/Start events. 我正在使用gpedit.msc脚本进行登录/注销/关机/启动事件。 The following PowerShell script runs on those events:
以下PowerShell脚本在这些事件上运行:
$web = New-Object System.Net.WebClient
[String] ${stUserDomain},[String] ${stUserAccount} = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name.split("\")
$str = $web.DownloadString("https://srv4923/event.php?username=" + ${stUserAccount} + "&workstation=" + $env:ComputerName + "&event=" + $args[0])
$str
The PHP script then generated an entry in a MySQL DB. 然后,PHP脚本在MySQL数据库中生成一个条目。 The script works perfectly fine for login and logout events but for shutdown/start events the username is not "myusername" anymore but it's "SYSTEM".
该脚本对于登录和注销事件非常有效,但是对于关机/启动事件,用户名不再是“ myusername”,而是“ SYSTEM”。 Can that prevented somehow by getting the username in a different way?
可以通过其他方式获取用户名来防止这种情况吗? I understand that when the boot event is triggered the user may not be logged in and therefore there is no username available.
我了解触发启动事件时,用户可能无法登录,因此没有可用的用户名。 But when the user shuts the machine down or reboots it, we should still know who did?
但是当用户关闭机器或重新启动机器时,我们仍然应该知道是谁做的?
As for this... 至于...
"...shutdown/start events ... myusername" anymore but it's "SYSTEM"...
“ ...关闭/启动事件... myusername”不再是,但是它是“ SYSTEM” ...
This is not a PowerShell code issue, but an OS by design requirement process. 这不是PowerShell代码问题,而是按设计要求的操作系统。
The simple answer is nope, as there will never be a user at startup. 简单的答案是不,因为启动时永远不会有用户。 It is always SYSTEM and has to be.
它始终是SYSTEM,必须存在。 The Windows MSGINA.dll does not kick in until the system is in a ready state, then it presents the MSGINA logon for the user, whether you decided to use a auto logon or not.
在系统处于就绪状态之前,Windows MSGINA.dll不会启动,然后无论用户是否决定使用自动登录,它都会为用户提供MSGINA登录。
You have to correlate the logoff and shutdown events to get who was last logged on before the shut down. 您必须关联注销和关闭事件,以获取关闭之前最后登录的用户。
Yet remember and admin can remote shutdown the system as can a scheduled task or even a power outage or electrical system surge. 但是请记住,管理员可以像计划任务甚至断电或电气系统电涌一样远程关闭系统。 So, even with that correlation, you have to keep that in mind.
因此,即使存在这种关联,也必须牢记这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.