Solved

Login Script for Machine Name and Network Info

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Learn about cloud computing and its benefits for small business owners.
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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