- 帖子
- 2
- 积分
- 14
- 技术
- 0
- 捐助
- 0
- 注册时间
- 2022-2-16
|
[问题求助] 求助vbs脚本,实现用户回家后还能记录登录和注销的信息在本地
下面这个脚本可以实现内网中用户登录和注销信息的收集,自动上传到远程服务器共享文件夹,
但是用户离开公司脱离域控环境后,就不能收集信息了,请各位大神帮加个判断,
如果用户不在内网环境比如:ping 不通远程服务器ip,就自动保存在本地文件夹,
可以ping通就上传到远程服务器共享文件夹。
On Error Resume Next
strComputerlyrj = "."
Set lianjieobjlinyangrj = GetObject("winmgmts:\\" & strComputerlyrj & "\root\cimv2")
Set colItemslinyangrj = lianjieobjlinyangrj.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItemlyrj in colItemslinyangrj
getcomputerstr = objItemlyrj.name
getcomputerdomainstr = objItemlyrj.Domain
getusernamestr = objItemlyrj.UserName
getmodelstr = objItemlyrj.Model & "(" & objItemlyrj.Manufacturer & ")"
next
Set colItemslinyangrj = nothing
Set ercolItemslinyangrj = lianjieobjlinyangrj.ExecQuery("Select * from Win32_OperatingSystem")
For Each erobjItemlyrj in ercolItemslinyangrj
getosnamestr = erobjItemlyrj.Caption
getoslastbootuptimestr = erobjItemlyrj.LastBootUpTime
next
Set ercolItemslinyangrj = nothing
Set lianjieobjlinyangrj = nothing
If getusernamestr <> "" Then
Else
Set SetobjNetlinyangrj = CreateObject("WScript.Network")
getusernamestr = SetobjNetlinyangrj.UserName
Set SetobjNetlinyangrj = nothing
End If
filenamestr = split(getusernamestr,"\")(ubound(split(getusernamestr,"\")))
getdatetimestr = replace(date(),"/","-") & " " & time()
存放文件的路径
pathstr = "\\192.168.118.128\shoujifile$\" & filenamestr & ".csv"
Set ofsolinyangrj = CreateObject("Scripting.FileSystemObject")
If ofsolinyangrj.fileExists(pathstr) Then
Set Outputlinyangrj = ofsolinyangrj.OpenTextFile(pathstr,8,True)
Outputlinyangrj.WriteLine """"& getcomputerstr &""","""& getcomputerdomainstr &""","""& getusernamestr &""","""& getdatetimestr &""",""登录"","""& getmodelstr &""","""& getosnamestr &""","""& getoslastbootuptimestr &""""
Outputlinyangrj.close()
Set Outputlinyangrj = nothing
else
Set Outputlinyangrj = ofsolinyangrj.CreateTextFile(pathstr, True)
Outputlinyangrj.WriteLine """计算机名称"",""登录域"",""登录名称"",""时间"",""类型"",""计算机型号"",""操作系统名称"",""最近一次开机时间"""
Outputlinyangrj.WriteLine """"& getcomputerstr &""","""& getcomputerdomainstr &""","""& getusernamestr &""","""& getdatetimestr &""",""登录"","""& getmodelstr &""","""& getosnamestr &""","""& getoslastbootuptimestr &""""
Outputlinyangrj.close()
Set Outputlinyangrj = nothing
end if
Set ofsolinyangrj = nothing |
|