Skip to content

Instantly share code, notes, and snippets.

@zyphlar
Created February 10, 2012 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zyphlar/1793697 to your computer and use it in GitHub Desktop.
Save zyphlar/1793697 to your computer and use it in GitHub Desktop.
Login Logging Script
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