Bom dia pessoal, sou novo aqui e estou precisando de uma ajuda. Preciso montar um script .vbs que quando o usuário se logue no dominio,esse script gere um log.txt com as seguintes informações:
data/hora de logon - hostname da máquina - login - ip da máquina - ip do Domain Controler que ele se autenticou
Eu só não estou conseguindo gerar o DC, o restante está tranquilo, segue abaixo o script com as informações.
Option Explicit
Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns, strComputer, objWMIService
Dim intConstants, intTimeout, strTitle, intCount, blnLog, IPconfigSet, Ipconfig, IP
Dim strUserName, strComputerName, strIP, strShare, strLogFile
Dim fso, sf, StrNew
Const ForAppending = 8
Set fso = CreateObject("Scripting.FileSystemObject")
strComputer = "."
strShare = "G:\"
strLogFile = "logonoff.txt"
intTimeout = 20
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Wscript.Shell")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
strUserName = objNetwork.UserName
strComputerName = objNetwork.ComputerName
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
IP = IPConfig.IPAddress(i)
Next
End If
Next
If objFSO.FolderExists(strShare) Then
On Error Resume Next
Set objLogFile = objFSO.OpenTextFile(strShare & "\" & strLogFile, 8, True, 0)
If Err.Number = 0 Then
intCount = 1
blnLog = False
Do Until intCount = 3
objLogFile.WriteLine "Logon " & Now & " " & strComputerName & " " & strUserName & " com o ip " & IP
If Err.Number = 0 Then
intCount = 3
blnLog = True
Else
Err.Clear
intCount = intCount + 1
If Wscript.Version > 5 Then
Wscript.Sleep 200
End If
End If
Loop
' On Error GoTo 0
End If
End If
Dim fa, fb, f, s, OpSysSet, i
Set objFSO = Nothing
Set objNetwork = Nothing
Set objShell = Nothing
Wscript.Quit
Pergunta
rpneves22
Bom dia pessoal, sou novo aqui e estou precisando de uma ajuda. Preciso montar um script .vbs que quando o usuário se logue no dominio,esse script gere um log.txt com as seguintes informações:
data/hora de logon - hostname da máquina - login - ip da máquina - ip do Domain Controler que ele se autenticou
Eu só não estou conseguindo gerar o DC, o restante está tranquilo, segue abaixo o script com as informações.
Option Explicit Dim objFSO, objLogFile, objNetwork, objShell, strText, intAns, strComputer, objWMIService Dim intConstants, intTimeout, strTitle, intCount, blnLog, IPconfigSet, Ipconfig, IP Dim strUserName, strComputerName, strIP, strShare, strLogFile Dim fso, sf, StrNew Const ForAppending = 8 Set fso = CreateObject("Scripting.FileSystemObject") strComputer = "." strShare = "G:\" strLogFile = "logonoff.txt" intTimeout = 20 Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = CreateObject("Wscript.Network") Set objShell = CreateObject("Wscript.Shell") Set IPConfigSet = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") strUserName = objNetwork.UserName strComputerName = objNetwork.ComputerName For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) IP = IPConfig.IPAddress(i) Next End If Next If objFSO.FolderExists(strShare) Then On Error Resume Next Set objLogFile = objFSO.OpenTextFile(strShare & "\" & strLogFile, 8, True, 0) If Err.Number = 0 Then intCount = 1 blnLog = False Do Until intCount = 3 objLogFile.WriteLine "Logon " & Now & " " & strComputerName & " " & strUserName & " com o ip " & IP If Err.Number = 0 Then intCount = 3 blnLog = True Else Err.Clear intCount = intCount + 1 If Wscript.Version > 5 Then Wscript.Sleep 200 End If End If Loop ' On Error GoTo 0 End If End If Dim fa, fb, f, s, OpSysSet, i Set objFSO = Nothing Set objNetwork = Nothing Set objShell = Nothing Wscript.QuitObrigado!
Editado por kuroiAdicionar tag CODE
Link para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.