Solved

Login Script for Machine Name and Network Info

Posted on 2009-04-07
4
169 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

867 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

20 Experts available now in Live!

Get 1:1 Help Now