+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, WMI Using 2 Classes in Coding and Web Development; Basically trying to use 2 WMI Classes in vbscript so that I can get the below information hopefully from one ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,675
    Thank Post
    3,209
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361

    WMI Using 2 Classes

    Basically trying to use 2 WMI Classes in vbscript so that I can get the below information hopefully from one query

    * MAC Address
    * Vendor
    * Link Speed ( as in current link speed not the maximum speed the NIC Can get or use )
    * Active / Status ( As in connected, not connected, obtaining ip address etc )
    * I.Pv4 Address
    * Subnet Mask
    * Default Gateway
    * DNS Servers
    * DHCP Servers
    * MTU of current Interface

    win32_NetworkAdapter allows you to get MAC Address, vendor, link status, link speed etc where as win32_NetworkAdapterConfiguration allows you to get ip address, subnet mask, default gateway, dhcp servers, dns servers and other info

    Currently have a HTA using vbscript and WMI but can only seem to do one query at a time ie one query on win32_NetworkAdapter and one query on win32_NetworkAdapterConfiguration but due to using NetworkAdapter to enumerate only physical network adapters into a dropdown menu I need it to pull the info for each relevant Interface each time you select a different interface from the drop down menu.
    @Steve21 and @Arthur or anyone else

    Thanks
    Last edited by mac_shinobi; 22nd April 2013 at 05:20 PM.

  2. #2
    bainer's Avatar
    Join Date
    Apr 2013
    Location
    West Yorkshire
    Posts
    8
    Thank Post
    0
    Thanked 3 Times in 3 Posts
    Rep Power
    0
    Can you share what you have already?

  3. Thanks to bainer from:

    mac_shinobi (1st May 2013)

  4. #3

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,675
    Thank Post
    3,209
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Also having issue(s) with the IP Address , as far as on some adapters that do not have an ip address ( version 4 or 6 ) you get an error message stating that the subscript range is out or does not exist so presume this is to do or related to me trying to split the results as originally it was outputting both the ipv4 and 6 addresses together on one line with a comma ie x.x.x.x, Y.Y.Y.Y

    Could do with help on how to get the IPv4 and the IPv6 addresses better ?
    @Chaddy - Is trying to help me with the CSS / GUI and could do with him re-uploading his version again as never got a chance to download his tweaked copy.

    Code:
    <head>
    <title>Network Utility</title>
    <style type="text/css">
        <!--
        body{
          background-color:Menu;
          color:MenuText;
          cursor:default;
          }
        -->
    table {
      -moz-border-radius: 6px; /* FF1+ */
      -webkit-border-radius: 6px; /* Saf3-4 */
      border-radius: 6px; /* Opera 10.5, IE9, Saf5, Chrome */
      -moz-box-shadow: 0 0 6px #959595 inset;
      -webkit-box-shadow: 0px 0px 6px #959595 inset; /* Saf3.0+, Chrome */
      box-shadow: 0px 0px 6px #959595 inset; /* Opera 10.5, IE9 */
      border-collapse:collapse;
      border: 5px solid black;
      color: #00769B;
      font-size: 1.1em;
      text-align: left;}
     </style>
    <HTA:APPLICATION 
         APPLICATIONNAME="Interface Info"
         SCROLL="yes"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="normal"
    
    </head>
    
    <script language="VBScript">
    Sub Window_Onload
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NOT PNPDeviceID LIKE 'ROOT\\%'") 'PhysicalAdapter ='true'") 
    
    For Each objItem in colItems
    Set objOption = Document.createElement("OPTION")
    objOption.Text = objItem.Description
    objOption.Value = objItem.Description
    NIC.Add(objOption)
    Next
    NIC.Focus
    End Sub
    
    Sub Obtain
    On Error Resume Next
    Dim MAC, Manu, NetStatus, LinkSpeed
    Dim IPvx, PName
    Dim x
    set objOption = window.event.srcElement
    
    
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colNA = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where Description ='" + objOption(objOption.selectedIndex).Text + "'")
    
    For Each objItem in colNA
    MAC = objItem.MACAddress
    Manu = objItem.Manufacturer
    NetStatus = objItem.NetConnectionStatus
    PName = objItem.ProductName
    Next
    
    Select Case NetStatus
    Case "0":
    NetStatus = "Disconnected"
    Case "1":
    NetStatus = "Connecting..."
    Case "2":
    NetStatus = "Connected"
    Case "3":
    NetStatus = "Dis-connecting"
    Case "4":
    NetStatus = "Hardware not present"
    Case "5":
    NetStatus = "Interface or Hardware disabled"
    Case "6":
    NetStatus = "Hardware malfunction"
    Case "7":
    NetStatus = "Media disconnected"
    Case "8":
    NetStatus = "Authenticating"
    Case "9":
    NetStatus = "Authentication succeeded"
    Case "10":
    NetStatus =  "Authentication failed"
    Case "11":
    NetStatus = "Invalid address"
    Case "12":
    NetStatus = "Credentials required"
    End Select
    
    Set colNAC = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where MACAddress='" + MAC + "'")
    
    For Each objItm in colNAC
        If IsArray(objItm.IPAddress) Then
            If UBound(objItm.IPAddress) = 0 Then
                strIP =  objItm.IPAddress(0)
            Else
                strIP =  Join(objItm.IPAddress, ",")
            End If
        End If
    Next
    
    IPvx = Split(strIP, ",")
    
    Set objWMI = GetObject("winmgmts://" & strComputer & "/root\WMI")
    Set colLinkSpeed = objWMI.ExecQuery("SELECT * FROM MSNdis_LinkSpeed Where InstanceName='" + objOption(objOption.selectedIndex).Text + "'") 
    For Each objItem in colLinkSpeed
        Speed = objItem.NdisLinkSpeed/(1000^2)*100 & " Mbps"
    Next
    
    Interface.innerhtml = "Hardware Address : " & MAC & "<p>" & "IPv4 Address : " & IPvx(0) & "<p>" & "IPv6 Address : " & IPvx(1) & "<p>" & "Link Speed : " & Speed & "<p>" & "Link Status : " & NetStatus & "<p>" & "Vendor : " & Manu & "<p>" & _
    "Product Name : " & PName
    
    End Sub
    
    </script>
    
    <body>
    Select a network interface for information:<p>
    <select size="1" name="NIC" OnFocus="Obtain()">
    </select>
    <p>Interface Information:<p>
    <table id="whitePanel" width="450px" cellpadding="0" cellspacing="0" border="0" >
    <td valign="top">
    <span id = "Interface"</span>
    </td>
    </table>
    
    
    
    
    
    </body>
    Chaddy did mention about the CSS to round the corners off only working in IE 9 or above, I have version 10 and the rounded corners still do not work, have mucked about with the css which I know is applying as I can change the colours and width of the borders which seem to apply fine but the border-radius and other things I am putting in the css are not applying as far as rounding the corners on the table

    Updated CSS :

    Code:
     
    <style type="text/css">
        <!--
        body{
          background-color:Menu;
          color:MenuText;
          cursor:default;
          }
        -->
    table {
    -webkit-border-radius:36px;
    -moz-border-radius:36px;
    border:5px solid;
    border-radius:36px;
    border-style:solid;
    border-color:#ff0000 #0000ff;
    border-collapse:collapse;}
     </style>
    See attached PNG Image
    Attached Images Attached Images
    Last edited by mac_shinobi; 1st May 2013 at 01:21 PM.

  5. #4

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,675
    Thank Post
    3,209
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Tried the code tweak that @Chaddy has done but it breaks MSHTA and other things which means the vbscript side does not work as it should , as per this article

    When using an HTA on IE9 the GetObject function is undefined when specifying X-UA-Compatible tag

    So how am I supposed to make it so that it supports and does the CSS / GUI and also allows the vbscript to work correctly

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 16
    Last Post: 1st September 2011, 08:35 AM
  2. Replies: 29
    Last Post: 7th November 2010, 01:41 AM
  3. Replies: 20
    Last Post: 25th January 2010, 12:59 PM
  4. Replies: 10
    Last Post: 8th May 2009, 12:20 PM
  5. Any one using Sharepoint or class server.?
    By tosca925 in forum Windows
    Replies: 11
    Last Post: 15th November 2005, 03:35 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •