PDA

View Full Version : Logon Script to log computer_name and ip_address (W2K)



poshanchang
07-01-2003, 02:05 AM
How can I log user's Computer_Name and Ip_Address to centralized SQL database server by using Windows 2000 Logon Script?

Sample code would be helpful ...
1) how to get ComputerName?
2) how to get IP_Address?
3) how to access DB by using WSH?

Thanks a lot.

Po-Shan.

jdharm
07-01-2003, 09:06 AM
I don't know how helpful this is, but this is the code of a vbs script that is executed in my domain when the user logs on to create a comma delimited text file that I can import into Excel. It records username, machine name, time and date on the client machine. Each user is added to the text file that I periodically clear when it has grown to around 350kb, about 8000 records. I'm not sure how to access the database, but maybe this will get you started in the right direction.

-----------------------------

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim f
Dim fso
Dim Person
Dim MachineName
Set WshNetwork = WScript.CreateObject("WScript.Network")
Person=WshNetwork.Username
MachineName=WshNetwork.ComputerName
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("\\server\userlogs\logonfile.txt", ForAppending, True)
f.Write Machinename & "," & Person & "," & Time & "," & Date & vbCrLf
f.Close
---------------------------------

Josh
<a target="_blank" href=http://www.jdharm.net>www.jdharm.net</a>

poshanchang
07-01-2003, 05:14 PM
Thanks so much. Is this logging to client's log file or the log file on the centralized server?

I'm also curious when logon script will only be ran when it's the successfully logon, right? What if there is a failure logon, how should I log the computer_name/ip_address/time/id?

Thanks a lot.

Po.

jdharm
07-08-2003, 11:39 AM
Is this logging to client's log file or the log file on the centralized server?

Yes, this is run my all machines, but the text is appened to the end of a single text file on a network share. That is what the path in line 10 is for. The \\server\userlogs\logfile.txt in line 10 is my path to the file being written to.

What if there is a failure logon, how should I log the computer_name/ip_address/time/id?

Yes, my little script is in the startup folders, so it will only be run after a successful login. The logs for an unsuccessful login are/can be recorded by the domain controler, though I'm not certain of the details of how or where these logs are kept.

Josh
<a target="_blank" href=http://www.jdharm.net>www.jdharm.net</a>