Created
February 10, 2012 22:49
-
-
Save zyphlar/1793697 to your computer and use it in GitHub Desktop.
Login Logging Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Error Resume Next | |
'''Variables | |
Dim wsNetwork | |
Dim outUser | |
Dim outComputer | |
Dim outIP | |
Dim logPath | |
Dim septxt | |
logPath = "\\EXAMPLE_SERVER\EXAMPLE_SHARE\logins.csv" | |
septxt = ", " | |
''''''''''''''''''''''''''''''''''''''' | |
' Computer Name Section | |
''''''''''''''''''''''''''''''''''''''' | |
Set wshShell = WScript.CreateObject( "WScript.Shell" ) | |
outComputer = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) | |
''''''''''''''''''''''''''''''''''''''' | |
' User Name Section | |
''''''''''''''''''''''''''''''''''''''' | |
set wsNetwork = createobject("WSCRIPT.Network") | |
outUser=wsNetwork.UserName | |
''''''''''''''''''''''''''''''''''''''' | |
' IP Address Section | |
''''''''''''''''''''''''''''''''''''''' | |
strComputer = "." | |
Set objWMIService = GetObject("winmgmts:" _ | |
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") | |
Set IPConfigSet = objWMIService.ExecQuery _ | |
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE") | |
outIP = "" | |
For Each IPConfig in IPConfigSet | |
If Not IsNull(IPConfig.IPAddress) Then | |
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) | |
outIP = outIP & IPConfig.IPAddress(i) & septxt | |
Next | |
End If | |
Next | |
''''''''''''''''''''''''''''''''''''''' | |
' Output Section | |
''''''''''''''''''''''''''''''''''''''' | |
Const ForAppending = 8 | |
Set objFSO = CreateObject("Scripting.FileSystemObject") | |
Set objTextFile = objFSO.OpenTextFile (logPath, ForAppending, True) | |
objTextFile.WriteLine(FormatDateTime(Now(), vbGeneralDate) & septxt & outUser & septxt & outComputer & septxt & outIP) | |
objTextFile.Close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment