Solved

Login Script for Machine Name and Network Info

Posted on 2009-04-07
4
168 Views
Last Modified: 2012-05-06
I would like a login scrip that can run on Windows XP and Windows Vista, for standard users (no admin access, not power users), that can write back to a directory on the network to a .txt file.  I would like this script to create a .txt file, or other format (.csv?), that creates the file and names it by the login name.  Such as, if the name is John Doe, it is John Doe.csv/.txt

Within the file, log the computer name that they login to.  I would also like to know if the network card is set to DHCP or Static.  If Static, provide the network address information, as well as the MAC address of the network card.

This can be .bat or .vbs - thanks
0
Comment
Question by:rosederekj
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
yehudaha earned 500 total points
ID: 24094577
change this line to share path (where save log files)

strShare = "\\server\share\"

Set objnet = CreateObject("wscript.network")

strShare = "\\server\share\"

strLog = strShare & objnet.UserName & ".txt"

Set objfso = CreateObject("scripting.filesystemobject")

Set objlog = objfso.CreateTextFile(strLog,True)
 
 

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 

Set colItems = objWMIService.ExecQuery _

    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 

For Each objItem in colItems

objlog.WriteLine objnet.ComputerName & ": DHCP Enabled: " & objItem.DHCPEnabled & vbnewline

    if objItem.DHCPEnabled = false Then

       objlog.WriteLine objItem.MACAddress

       For Each strAddress in objItem.IPAddress

         objlog.WriteLine strAddress & vbcrlf

       Next

    End If

Next

Open in new window

0
 

Author Comment

by:rosederekj
ID: 24094730
That's great, worked almost perfect except doesn't seem to log MAC address.  Not a big deal though as I have other methods of getting that.

One last request, can I get the script to append to the file?  Such as, when John Doe logs into ComputerA, and then Computer B, I want the file to show both.  I don't need every instance of ComputerA or ComputerB, just to know that he has logged into those machines, and the corresponding DHCP status.
0
 
LVL 14

Assisted Solution

by:yehudaha
yehudaha earned 500 total points
ID: 24094781
hey

the script will log mac address as you requested to only static addresses (tested)
if you want to log the mac in any case

after line 16 add this line

objlog.WriteLine "Mac Address: " &  objItem.MACAddress

any way

i changed the script to check if a log file with the user all ready exist if yes it will open it and add a new section to the current computer
Set objfso = CreateObject("scripting.filesystemobject")

Set objnet = CreateObject("wscript.network")

strShare = "\\server\share\"

strLog = strShare & objnet.UserName & ".txt"

If objfso.FileExists(strLog) Then

Const ForAppend = 8 

Set objlog = objfso.OpenTextFile(strLog,ForAppend)

Else

Set objlog = objfso.CreateTextFile(strLog,True)

End If

 

 

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _

    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

 

Set colItems = objWMIService.ExecQuery _

    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

 

For Each objItem in colItems

objlog.WriteLine objnet.ComputerName & ": DHCP Enabled: " & objItem.DHCPEnabled & vbnewline

    if objItem.DHCPEnabled = false Then

       objlog.WriteLine objItem.MACAddress

       For Each strAddress in objItem.IPAddress

         objlog.WriteLine strAddress & vbcrlf

       Next

    End If

Next

Open in new window

0
 

Author Closing Comment

by:rosederekj
ID: 31567690
Excellent - thanks!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now