Страница 1 из 1

Кто когда залогинился

Добавлено: 2008-10-18 0:58:39
slim
Автору сенкс :smile:
А дальше с файлов в базу, одно но автор записывал вход выход и иногда по его словам были грабли с доступом к файлу ( он писал в один файл ), чуть изменил но время выхода из домена мне не оч интересно.

Код: Выделить всё

on error resume next
wYYYY = DatePart("YYYY" , Now)
wMM = DatePart("M" , Now)
If Len(wMM) = 1 Then
wMM = "0" & wMM
End If
wHH = DatePart("h", Now)
If Len(wHH) = 1 Then
wHH = "0" & wHH
End If
wNN = DatePart("n", Now)
If Len(wNN) = 1 Then
wNN = "0" & wNN
End If
wSS = DatePart("s", Now)
If Len(wSS) = 1 Then
wSS = "0" & wSS
End If


strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set IPConfigSet = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")




Curtime = wHH & ":" & wNN & ":" &wSS
Set WshShell = CreateObject("WScript.Shell")
CompName = WshShell.ExpandEnvironmentStrings("%computername%")
UserName = WshShell.ExpandEnvironmentStrings("%username%")
Curdate = (FormatDateTime(date(),vbgeneraldate))
Dim objFSO, objFolder, objShell, objTextFile, objFile
Dim strDirectory, strFile, strText
strDirectory = "g:\w_opday\log\userlogin\"
strMonthDirectory = (wYYYY &""& wMM)
strFile = ("\" & username & ".log")


For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then 
        For Each IPAddress In IPConfig.IPAddress
           ipAddr = + IPAddress
        Next
    End If
Next

strTextOFF = ("LOGOFF | " & Curdate & " at " & Curtime & " | " & Compname & vbTab & ipAddr & vbTab &"-> "& username )
strTextON = ("| " & Curdate & " at " & Curtime & " | " & Compname & vbTab & ipAddr & vbTab &"<- "& username)
WTODO = Wscript.Arguments.Item(0) 'cmd argument

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Check that the strDirectory folder exists
If not objFSO.FolderExists(strDirectory) Then
    WScript.Quit
End if
If not objFSO.FolderExists(strDirectory & strMonthDirectory) Then
Set objFolder = objFSO.CreateFolder(strDirectory & strMonthDirectory)
End if

If not objFSO.FileExists(strDirectory & strMonthDirectory & strFile) Then
Set objFile = objFSO.CreateTextFile(strDirectory & strMonthDirectory & strFile)
End If

set objFile = nothing
set objFolder = nothing
Const ForAppending = 8

Set objTextFile = objFSO.OpenTextFile _
(strDirectory & strMonthDirectory & strFile, ForAppending, True)

objTextFile.WriteLine(strTextON)


objTextFile.Close

WScript.Quit 
В итоге получается
G:\w_opday\log\userlogin\200810\slim.log

Код: Выделить всё

| 06.10.2008 at 08:19:39 | SLIM	10.10.145.116	<- slim

Но формат каждый подбирает как его удобней анализировать, мне так.

Re: Кто когда залогинился

Добавлено: 2008-10-29 17:33:06
Alex Keda
о чём вы? =)