![登录时显示一个对话框询问登录原因 - Windows Server](https://linux22.com/image/803154/%E7%99%BB%E5%BD%95%E6%97%B6%E6%98%BE%E7%A4%BA%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%AF%9D%E6%A1%86%E8%AF%A2%E9%97%AE%E7%99%BB%E5%BD%95%E5%8E%9F%E5%9B%A0%20-%20Windows%20Server%20.png)
我正在寻找一种方法,在登录生产服务器时显示一个输入对话框,要求用户说明登录的原因。我在想,也许 Windows 中有一种方法可以做到这一点,类似于服务器重新启动时显示的关机对话框。
我查看了组策略,但找不到任何有用的东西。我知道这可以通过脚本完成,但在开始编写之前,我想看看 Windows 中是否有任何集成的方法。
谢谢
答案1
我最终编写了以下 VBScript,并将其设置为在 GPO 中登录时运行
' Display an input dialog asking the reason for a login and writes it to the event viewer with information of the user.
Const EVENT_TYPE = "Information" 'Available Values: Success, Error, Warning, Information
Const EVENT_SOURCE = "LoginAudit" 'Setting the event source requires that the script runs with administrative privileges
firstname = GetUserFirstname()
username = GetUsername()
loginReason = ""
Do While (loginReason = "")
loginReason = InputBox("Hi " + firstname + ", please describe the reason of your login:", "Login Audit")
Loop
eventDescription = "User '" & username & "' logged in, providing the following reason: " & Chr(13) & Chr(13) & loginReason
Set WshShell = WScript.CreateObject("WScript.Shell")
strCommand = "eventcreate /T " & EVENT_TYPE & " /ID 100 /L Application /SO LoginAudit /D " & _
Chr(34) & eventDescription & Chr(34)
WshShell.Run strcommand
Function GetUserFirstname()
Set objSysInfo = CreateObject("ADSystemInfo")
Set objCurrentUser = GetObject("LDAP://" & objSysInfo.UserName)
GetUserFirstname = objCurrentUser.givenName
End Function
Function GetUsername()
Set objNetwork = CreateObject("Wscript.Network")
GetUsername = objNetwork.UserName
End Function
答案2
在开始编写之前,我想看看 Windows 中是否有任何集成的方法。
没有。恐怕你得自己写。也许有第三方应用程序可以满足你的要求,但恐怕产品/服务推荐与 Server Fault 无关。