Home All Groups Group Topic Archive Search About


Author
26 Oct 2007 12:08 AM
Rename my folders
someone posted this script below to record the logon of a user in a sql db. 
It works fine but I want to also capture the IP address of the person logging
onto the domain.  How do I do that?:

Option Explicit

Dim strServer, strInstance, strDatabase, strConnect
Dim adoConnection, adoCommand, objNetwork
Dim strUserName, strComputerName, strSQL

' Specify SQL Server, Instance name (if any), and database.
strServer = "MyServer"
strInstance = "MyInstance"
strDatabase = "MyDatabase"
strServer = "Idaho"
strInstance = "PocketLunch"
strDatabase = "PocketLunch"

If (strInstance <> "") Then
    strServer = strServer & "\" & strInstance
End If

' Connection string for database.
' This uses Windows Authentication.
strConnect = "DRIVER=SQL Server;" _
    & "Trusted_Connection=Yes;" _
    & "DATABASE=" & strDatabase & ";" _
    & "SERVER=" & strServer

' Create ADO objects and connect to database.
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.ConnectionString = strConnect
adoConnection.Open

Set adoCommand = CreateObject("ADODB.Command")
adoCommand.ActiveConnection = adoConnection

' Retrieve values.
Set objNetwork = CreateObject("Wscript.Network")
strUserName = objNetwork.UserName
strComputerName = objNetwork.ComputerName

' Log date/time, user name, and computer name.
strSQL = "INSERT INTO MyTable " _
    & "(LogonDate, UserName, ComputerName) " _
    & "VALUES(" _
        & "GETDATE(), " _
        & "'" & strUserName & "', " _
        & "'" & strComputerName & "'" _
    & ")"
adoCommand.CommandText = strSQL
adoCommand.Execute

' Clean up.
adoConnection.Close

AddThis Social Bookmark Button