none
Help with VBS? RRS feed

  • Question

  • Good morning/afternoon everyone!

    This may be the wrong place to post for help – if so, please direct me to the correct forum.  I am hoping to use the script below to retrieve the MAC address for all adapters and although it is working, I am only getting information on connected devices.  If possible, I would like to see MACs for all hardware, not just ones in use. 

    Can anyone help with this?  

    On Error Resume Next
    strComputer = "."
    
    'Location the script is running from
    Set objShell = CreateObject("Wscript.Shell")
    strPath = Wscript.ScriptFullName
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(strPath)
    strFolder = objFSO.GetParentFolderName(objFile) 
    
    'Progress Bar
    Set objExplorer = CreateObject _
        ("InternetExplorer.Application")
    objExplorer.Navigate "about:blank"   
    objExplorer.ToolBar = 0
    objExplorer.StatusBar = 0
    objExplorer.Width = 400
    objExplorer.Height = 100 
    objExplorer.Visible = 1             
    objExplorer.Document.Title = "VBS Script in Progress"
    objExplorer.Document.Body.InnerHTML = "The Script is gathering system information. " _
        & "This might take several minutes to complete."
    
    'Get Computer Name
    Set objComputer = CreateObject("Shell.LocalMachine")
    SysName = objComputer.MachineName
    
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
    
    'Create output File
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objNewFile = objFS.CreateTextFile(strFolder & "\" & SysName & ".htm")
    objNewFile.WriteLine "<html>"
    objNewFile.WriteLine "<title>" & SysName & "</title>"
    
    'Write to File for system Info
    For Each objItem In colItems
    	objNewFile.WriteLine "Computer Name: " & objItem.Name
    	'objNewFile.WriteLine "Description: " & objItem.Description
    	objNewFile.WriteLine "<br>Domain: " & objItem.Domain
    	Select Case objItem.DomainRole
    		Case 0 strDomainRole = "Standalone Workstation"
    		Case 1 strDomainRole = "Member Workstation"
    		Case 2 strDomainRole = "Standalone Server"
    		Case 3 strDomainRole = "Member Server"
    		Case 4 strDomainRole = "Backup Domain Controller"
    		Case 5 strDomainRole = "Primary Domain Controller"
    	End Select
    	objNewFile.WriteLine "<br>Domain Role: " & strDomainRole
    	objNewFile.WriteLine "<br>Current Time Zone (Hours Offset From GMT): " & (objItem.CurrentTimeZone / 60)
    	objNewFile.WriteLine "<br>Daylight Saving In Effect: " & objItem.DaylightInEffect
    	objNewFile.WriteLine "<br>Current logged on user: " & objItem.UserName
    	objNewFile.WriteLine "<br>Script run: " & Now()
    	objNewFile.WriteLine "<br>"
    	objNewFile.WriteLine "<br>**************************************"
    	objNewFile.WriteLine "<br>System Information"
    	objNewFile.WriteLine "<br>&nbspManufacturer: " & objItem.Manufacturer
    	objNewFile.WriteLine "<br>&nbspModel: " & objItem.Model
    	For Each strOEMStringArray in objItem.OEMStringArray
    		objNewFile.WriteLine "<br>&nbsp&nbspOEM Info: " & strOEMStringArray
    	Next
    		objNewFile.WriteLine "<br>&nbspTotal Physical Memory: " & FormatNumber(objItem.TotalPhysicalMemory / 1048576,2) & " Mb"
    Next
    
    'Network Information
    	objNewFile.WriteLine "<br><br>**************************************<br>Network Information"
    Set colAdapters = objWMIService.ExecQuery _
        ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
     n = 1
    objNewFile.WriteLine
    For Each objAdapter in colAdapters
       objNewFile.WriteLine "<br>Network Adapter " & n
       objNewFile.WriteLine "<br>================="
       objNewFile.WriteLine "<br>&nbsp&nbspDescription: " & objAdapter.Description
       objNewFile.WriteLine "<br>&nbsp&nbspPhysical (MAC) address: " & objAdapter.MACAddress
       objNewFile.WriteLine "<br>&nbsp&nbspHost name:              " & objAdapter.DNSHostName
       If Not IsNull(objAdapter.IPAddress) Then
          For i = 0 To UBound(objAdapter.IPAddress)
             objNewFile.WriteLine "<br>&nbsp&nbspIP address:             " & objAdapter.IPAddress(i)
          Next
       End If
       If Not IsNull(objAdapter.IPSubnet) Then
          For i = 0 To UBound(objAdapter.IPSubnet)
             objNewFile.WriteLine "<br>&nbsp&nbspSubnet:                 " & objAdapter.IPSubnet(i)
          Next
       End If
       If Not IsNull(objAdapter.DefaultIPGateway) Then
          For i = 0 To UBound(objAdapter.DefaultIPGateway)
             objNewFile.WriteLine "<br>&nbsp&nbspDefault gateway:        " & _
                 objAdapter.DefaultIPGateway(i)
          Next
       End If
       objNewFile.WriteLine "<br>"
       objNewFile.WriteLine "<br>&nbsp&nbspDNS"
       objNewFile.WriteLine "<br>&nbsp&nbsp---"
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbspDNS servers in search order:"
       If Not IsNull(objAdapter.DNSServerSearchOrder) Then
          For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
             objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbsp&nbsp" & objAdapter.DNSServerSearchOrder(i)
          Next
       End If
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspDNS domain: " & objAdapter.DNSDomain
       If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
          For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
             objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspDNS suffix search list: " & _
                 objAdapter.DNSDomainSuffixSearchOrder(i)
          Next
       End If
       objNewFile.WriteLine "<br>"
       objNewFile.WriteLine "<br>&nbsp&nbspDHCP"
       objNewFile.WriteLine "<br>&nbsp&nbsp----"
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspDHCP enabled:        " & objAdapter.DHCPEnabled
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspDHCP server:         " & objAdapter.DHCPServer
       If Not IsNull(objAdapter.DHCPLeaseObtained) Then
          utcLeaseObtained = objAdapter.DHCPLeaseObtained
          strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
       Else
          strLeaseObtained = ""
       End If
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspDHCP lease obtained: " & strLeaseObtained
       If Not IsNull(objAdapter.DHCPLeaseExpires) Then
          utcLeaseExpires = objAdapter.DHCPLeaseExpires
          strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
       Else
          strLeaseExpires = ""
       End If
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspDHCP lease expires:  " & strLeaseExpires
       objNewFile.WriteLine "<br>"
       objNewFile.WriteLine "<br>&nbsp&nbspWINS"
       objNewFile.WriteLine "<br>&nbsp&nbsp----"
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspPrimary WINS server:   " & objAdapter.WINSPrimaryServer
       objNewFile.WriteLine "<br>&nbsp&nbsp&nbsp&nbspSecondary WINS server: " & objAdapter.WINSSecondaryServer
       objNewFile.WriteLine "<br>"
       n = n + 1
    
    Next
    
    objNewFile.Close
    objExplorer.Quit
    

    Monday, July 27, 2015 4:07 PM

Answers

  • This gets all MAC addresses.

    "SELECT * FROM win32_networkadapter WHERE MacAddress IS NOT NULL"


    \_(ツ)_/

    • Marked as answer by mjannise Monday, July 27, 2015 5:05 PM
    Monday, July 27, 2015 4:39 PM

All replies