1. 程式人生 > >使用組策略記數數據庫用戶登入終端

使用組策略記數數據庫用戶登入終端

xpl val database drive acc comm scrip sin second

1:在域管理服務器上,打開組策略
2:新建一個組策略,名為GetUserInfo
3:打開組策略,用戶登入時執處GetuserInfo.vbs腳本在域模式下,記錄用戶登入計算機數據庫

Option Explicit

Dim con
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)

userName = objUser.sAMAccountName
displayName = objUser.displayName

telephone = objUser.telephoneNumber

Set WshNetwork = WScript.CreateObject("WScript.Network")
computerName = WshNetwork.ComputerName

serverIP = Wscript.Arguments(0)
serverDB = Wscript.Arguments(1)
serverUSer = Wscript.Arguments(2)
serverPW = Wscript.Arguments(3)

CurrentTime=Year(Now)&"-"&Month(Now)&"-"&day(Now)&" "&Hour(Now)&":"&Minute(Now)&":"&Second(Now)

set con = wscript.CreateObject("ADODB.Connection")
ConStr = "driver={sql server};Server=" + serverIP + ";Database=" + serverDB + ";uid=" + serverUSer + ";pwd=" + serverPW +";"
con.Open ConStr
‘ 刪 除在同一終端機上的登入記錄,只保留最新登入記錄
command = "delete from username where computername = ‘" + computername + "‘ and username = ‘" + userName + "‘"

con.Execute(command)

command = "insert into username (username,computername,logintime,displayName,telephone) values (‘"
command = command + userName + "‘,‘" + computerName + "‘,‘" + CurrentTime + "‘,‘" + displayName + "‘,‘" + telephone + "‘)"
con.Execute(command)

con.Close()

使用組策略記數數據庫用戶登入終端