Usuário com melhor resposta
Script Gravar Usuário que faz Logoff

Pergunta
-
Preciso de um script para rodar na GPO no logoff do usuário. Quero que seja gravado em um arquivo texto
o nome do usuário, máquina, data e hora do logoff. Não sei se é possível também na finalização da máquina ter um script para gravar a data e hora que a máquina foi desligada.
Obrigado.
Respostas
-
Olá Marsene,
Criei o script abaixo e estou usando na minha rede.
Option Explicit
Dim objFSO, objLogtxt, objNetwork, objShell, strText, intAns
Dim intConstants, intTimeout, strTitle, intCount, blnLog, data, systime
Dim strUserName, strComputerName, strIP, strShare, strLogFile, local
Dim fso, sf, StrNew
Const ForAppending = 8
systime = Now()
data= cstr(day(systime)& "-" & cstr(month(systime)) & "-" & cstr(year(systime)))
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Wscript.Shell")
Set local= CreateObject("Scripting.FileSystemObject")strUserName = objNetwork.UserName
strComputerName = objNetwork.ComputerName
If (local.FileExists("\\server\folder\"& data & ".txt")) Then
strShare = "\\server\folder\"
strLogFile = ""& data & ".txt"
If objFSO.FolderExists(strShare) Then
Set objLogtxt = objFSO.OpenTextFile(strShare & "\" & strLogFile, 8, True, 0)
If Err.Number = 0 Then
intCount = 1
blnLog = False
Do Until intCount = 3
objLogtxt.WriteLine"Logoff, " & strUserName &", "&data&", " & Time &", "& strComputerName
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
End If
End If
else
strShare = "\\server\folder\"
strLogFile = ""& data & ".txt"
intTimeout = 20
If objFSO.FolderExists(strShare) Then
Set objLogtxt = objFSO.OpenTextFile(strShare & "\" & strLogFile, 8, True, 0)
objLogtxt.WriteLine " Evento, "&" Usuário,"& " Data,"& " Horas , "&" Computador "
If Err.Number = 0 Then
intCount = 1
blnLog = False
Do Until intCount = 3
objLogtxt.WriteLine "Logoff, " & strUserName &", "&data&", " &Time &", "& strComputerName
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
End If
End IfEnd If
Espero te ajudado.
Saulo Januzzi
Se este script ajudou, não esqueça de classifica-lo.
Todas as Respostas
-
Veja como seria com um arquivo .cmd:
echo date /t >> \\server\suporte$\logoff.txt
echo %username% >> \\server\suporte$\logoff.txt
--
Vinicius Canto
MVP Windows Server - Admin Frameworks
MCP Windows 2000 Server, Windows XP e SQL Server 2000
Bacharelando em Ciências da Computação - USP
Blog sobre Scripting e Windows Powershell: http://viniciuscanto.blogspot.com -
Olá Marsene,
Criei o script abaixo e estou usando na minha rede.
Option Explicit
Dim objFSO, objLogtxt, objNetwork, objShell, strText, intAns
Dim intConstants, intTimeout, strTitle, intCount, blnLog, data, systime
Dim strUserName, strComputerName, strIP, strShare, strLogFile, local
Dim fso, sf, StrNew
Const ForAppending = 8
systime = Now()
data= cstr(day(systime)& "-" & cstr(month(systime)) & "-" & cstr(year(systime)))
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Set objShell = CreateObject("Wscript.Shell")
Set local= CreateObject("Scripting.FileSystemObject")strUserName = objNetwork.UserName
strComputerName = objNetwork.ComputerName
If (local.FileExists("\\server\folder\"& data & ".txt")) Then
strShare = "\\server\folder\"
strLogFile = ""& data & ".txt"
If objFSO.FolderExists(strShare) Then
Set objLogtxt = objFSO.OpenTextFile(strShare & "\" & strLogFile, 8, True, 0)
If Err.Number = 0 Then
intCount = 1
blnLog = False
Do Until intCount = 3
objLogtxt.WriteLine"Logoff, " & strUserName &", "&data&", " & Time &", "& strComputerName
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
End If
End If
else
strShare = "\\server\folder\"
strLogFile = ""& data & ".txt"
intTimeout = 20
If objFSO.FolderExists(strShare) Then
Set objLogtxt = objFSO.OpenTextFile(strShare & "\" & strLogFile, 8, True, 0)
objLogtxt.WriteLine " Evento, "&" Usuário,"& " Data,"& " Horas , "&" Computador "
If Err.Number = 0 Then
intCount = 1
blnLog = False
Do Until intCount = 3
objLogtxt.WriteLine "Logoff, " & strUserName &", "&data&", " &Time &", "& strComputerName
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
End If
End IfEnd If
Espero te ajudado.
Saulo Januzzi
Se este script ajudou, não esqueça de classifica-lo.
-
-
Veja como ficaria com um BAT:
for /f "tokens=*" %%i in ('date /t') do set dt=%%i
echo %username%,%dt% >> \\server\share\teste.csv
Aí é só importar o CSV no Excel. Pra isso, procure sobre recursos de obtenção de dados externos no Excel.
[]s,
--
Vinicius Canto
MVP Windows Server - Admin Frameworks
MCP Windows 2000 Server, Windows XP e SQL Server 2000
Bacharelando em Ciências da Computação - USP
Blog sobre Scripting e Windows Powershell: http://viniciuscanto.blogspot.com -
-
-