Skip to content

Instantly share code, notes, and snippets.

@zyphlar zyphlar/logging.vbs

Created Feb 10, 2012
Embed
What would you like to do?
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
You can’t perform that action at this time.