Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Login Script for Machine Name and Network Info

Posted on 2009-04-07
4
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
yehudaha earned 2000 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 2000 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

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.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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