Scripting VBS Windows Windows XP

Local IP Address & Computer Name Auto Email

Working in an office environment, sometimes I need to find out the computer name and IP Address of a computer on the local network. In the past we used to get the user to run “ipconfig” on a command prompt and email us the Address.
To make it simpler for the users I have created a script that will find the IP Address of the PC and the Computer name along with the user who generated it.
Hope this helps someone else out.

'===================================================================================
'
' FILE: IPAddress.vbs
'
' OPTIONS: No Options, used as a library 
' REQUIREMENTS: vbs ver 5.0 or greater
' BUGS: 
' NOTES: 
' AUTHOR: Ketan Desai
' COPYRIGHT: KETAN DESAI
' VERSION: 1.0
' CREATED: 15.08.2013
'===================================================================================

Option Explicit
Dim strQuery, objWMIService, colItems, objItem, objNetwork, strIP, userName, ComputerName, objMessage, ToEmail, FromEmaildomain, MailServer

'===================================================================================
' Veriables - You will only need to change the following section
'===================================================================================

ToEmail="Helpdesk@ketandesai.co.uk"			
FromEmaildomain="@ketandesai.co.uk"			'Email Domin of your mail server
MailServer="smtpserver.domin.local"

'===================================================================================
' Get IP Address of Computer
'===================================================================================
strQuery = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE DHCPEnabled=1"

Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )

For Each objItem In colItems
    If IsArray( objItem.IPAddress ) Then
        If UBound( objItem.IPAddress ) = 0 Then
            strIP = "IP Address: " & objItem.IPAddress(0)
        Else
            strIP = "IP Addresses: " & Join( objItem.IPAddress, "," )
        End If
    End If
Next

'===================================================================================
' Get UserName of Person Loged in & Get Computer Name
'===================================================================================

Set objNetwork = CreateObject("WScript.Network") 
userName = objNetwork.UserName 
ComputerName = objNetwork.ComputerName   

'===================================================================================
' Send Email to Support Desk
'===================================================================================
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = "User: " & userName & " from:" & ComputerName
objMessage.From = userName & FromEmaildomain 
objMessage.To = ToEmail 
objMessage.TextBody = "IP Address of " & userName & " Workstation |" & ComputerName & "|" & strIP

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = MailServer

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send


Set objMessage = CreateObject("CDO.Message") 

Leave a Reply

Your email address will not be published. Required fields are marked *