Solved

Login Script for Machine Name and Network Info

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Modifying Powershell and WMI to obtain disk, cpu, mem & IP data ? 5 58
Big Problem with Redirected Folder 8 44
Attention Please 10 43
Batch file or script with password 22 44
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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