Announcement

Collapse
No announcement yet.

VBS Output to html file

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS Output to html file

    Hi,
    I have got the following script. How would I tweak it to save the output to an html file?
    Code:
     
    On Error Resume Next
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    arrComputers = Array("localhost")
    For Each strComputer In arrComputers
       WScript.Echo
       WScript.Echo "=========================================="
       WScript.Echo "Computer: " & strComputer
       WScript.Echo "=========================================="
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
       For Each objItem In colItems
          'WScript.Echo "AdapterType: " & objItem.AdapterType
          'WScript.Echo "AdapterTypeId: " & objItem.AdapterTypeId
         ' WScript.Echo "AutoSense: " & objItem.AutoSense
          'WScript.Echo "Availability: " & objItem.Availability
          'WScript.Echo "Caption: " & objItem.Caption
          'WScript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
          'WScript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
          'WScript.Echo "CreationClassName: " & objItem.CreationClassName
          WScript.Echo "Description: " & objItem.Description
          'WScript.Echo "DeviceID: " & objItem.DeviceID
          'WScript.Echo "ErrorCleared: " & objItem.ErrorCleared
          'WScript.Echo "ErrorDescription: " & objItem.ErrorDescription
          'WScript.Echo "GUID: " & objItem.GUID
          'WScript.Echo "Index: " & objItem.Index
          'WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
          'WScript.Echo "Installed: " & objItem.Installed
          'WScript.Echo "InterfaceIndex: " & objItem.InterfaceIndex
          'WScript.Echo "LastErrorCode: " & objItem.LastErrorCode
          WScript.Echo "MACAddress: " & objItem.MACAddress
          WScript.Echo "Manufacturer: " & objItem.Manufacturer
          'WScript.Echo "MaxNumberControlled: " & objItem.MaxNumberControlled
          'WScript.Echo "MaxSpeed: " & objItem.MaxSpeed
          WScript.Echo "Name: " & objItem.Name
          WScript.Echo "NetConnectionID: " & objItem.NetConnectionID
          WScript.Echo "NetConnectionStatus: " & objItem.NetConnectionStatus
          'WScript.Echo "NetEnabled: " & objItem.NetEnabled
          strNetworkAddresses = Join(objItem.NetworkAddresses, ",")
             WScript.Echo "NetworkAddresses: " & strNetworkAddresses
          WScript.Echo "PermanentAddress: " & objItem.PermanentAddress
          WScript.Echo "PhysicalAdapter: " & objItem.PhysicalAdapter
          'WScript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
          strPowerManagementCapabilities = Join(objItem.PowerManagementCapabilities, ",")
             'WScript.Echo "PowerManagementCapabilities: " & strPowerManagementCapabilities
          'WScript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
          'WScript.Echo "ProductName: " & objItem.ProductName
          'WScript.Echo "ServiceName: " & objItem.ServiceName
         ' WScript.Echo "Speed: " & objItem.Speed
          'WScript.Echo "Status: " & objItem.Status
          'WScript.Echo "StatusInfo: " & objItem.StatusInfo
          'WScript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
          WScript.Echo "SystemName: " & objItem.SystemName
          'WScript.Echo "TimeOfLastReset: " & WMIDateStringToDate(objItem.TimeOfLastReset)
          WScript.Echo
       Next
    Next
     
    Function WMIDateStringToDate(dtmDate)
    WScript.Echo dtm: 
     WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
     Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
     & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    End Function
    Thanks
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

  • #2
    Re: VBS Output to html file

    Sorted now (With a little help from a friend)
    Not sure if its the most elegant way of doing it but it works.

    Code:
     
    On Error Resume Next
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    Set objFS = CreateObject("Scripting.FileSystemObject")
    Set objNewFile = objFS.CreateTextFile("C:\GetMac.htm")
    objNewFile.WriteLine "<html>"
    objNewFile.WriteLine "<head>"
    objNewFile.WriteLine "<title>UAG Client information</title>"
    objNewFile.WriteLine "</head>"
    objNewFile.WriteLine "<body>"
    objNewFile.WriteLine "<h1>UAG Client Information -- Date: " & Now() & _
        "</h1>" & vbCrLf
    objNewFile.WriteLine "<style>table {font-size: 10pt; font-family: arial;}th {background-color: buttonface; font-decoration: bold;}</style><table BORDER=""1""><tr><th>Property</th><th>Value</th></tr><tr bgcolor=""yellow""><td>Computer</td><td>&nbsp;localhost</td></tr>"
     
    arrComputers = Array("localhost")
    For Each strComputer In arrComputers
       
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
       For Each objItem In colItems
          
    objNewFile.WriteLine "<tr><td>Description</td><td>&nbsp;" & objItem.Description & "</td></tr>"
    objNewFile.WriteLine "<tr><td>MACAddress</td><td>&nbsp;" & objItem.MACAddress & "</td></tr>"
    objNewFile.WriteLine "<tr><td>Name</td><td>&nbsp;" & objItem.Name & "</td></tr>"
    objNewFile.WriteLine "<tr><td>NetConnectionID</td><td>&nbsp;" & objItem.NetConnectionID & "</td></tr>"
    objNewFile.WriteLine "<tr><td>PhysicalAdapter</td><td>&nbsp;" & objItem.PhysicalAdapter & "</td></tr>"
    objNewFile.WriteLine "<tr><td>SystemName</td><td>&nbsp;" & objItem.SystemName & "</td></tr>"
     Next
    Next
    objNewFile.WriteLine "</body>"
    objNewFile.WriteLine "</html>"
    Function WMIDateStringToDate(dtmDate)
    WScript.Echo dtm: 
     WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
     Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
     & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    End Function
    Caesar's cipher - 3

    ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

    SFX JNRS FC U6 MNGR

    Comment


    • #3
      Re: VBS Output to html file

      Originally posted by L4ndy View Post
      Sorted now (With a little help from a friend)
      one detail,
      in your script there is this line: For Each strComputer In arrComputers
      what means that the script is written in a way that it also can run against multiple computers.

      In your friend's version of the script the computer name (strComputer) is hard coded,
      "<tr bgcolor=""yellow""><td>Computer</td><td>&nbsp;localhost</td></tr>"
      and this is before the first For-next statement.


      In the sample below I also added the html <end of table> tag and, the close file statement,
      Code:
      Const wbemFlagReturnImmediately = &h10
      Const wbemFlagForwardOnly = &h20
      
      Set objFS = CreateObject("Scripting.FileSystemObject")
      Set objNewFile = objFS.CreateTextFile("GetMac.htm")
      
      On Error Resume Next
      
      a =    "<style>"
      a = a& "BODY{background-color:Lavender ;}"
      a = a& "TABLE{font-size: 10pt; font-family: arial;}"
      a = a& "TH{background-color: buttonface; font-decoration: bold;}"
      a = a& "</style>"
      
      objNewFile.WriteLine "<html>"
      objNewFile.WriteLine "<head>"
      objNewFile.WriteLine "<title>UAG Client information</title>"
      objNewFile.WriteLine a & "</head><body>"
      objNewFile.WriteLine "<h2>UAG Client Information -- Date: " _
         & Now() & "</h2>"
      
      
      arrComputers = Array("localhost")
      
      For Each strComputer In arrComputers
      
         objNewFile.WriteLine "<strong>Computer:&nbsp;" & strComputer & "</strong>"
      
         objNewFile.WriteLine "<table BORDER=""1"">"
         objNewFile.WriteLine "<tr><th>Property</th><th>Value</th></tr>"
         
         Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
         Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _
                                                wbemFlagReturnImmediately + wbemFlagForwardOnly)
      
         For Each objItem In colItems
           objNewFile.WriteLine "<tr bgcolor=""yellow""><td>Name</td><td>&nbsp;" & objItem.Name & "</td></tr>"
           objNewFile.WriteLine "<tr><td>MACAddress</td><td>&nbsp;" & objItem.MACAddress & "</td></tr>"
           objNewFile.WriteLine "<tr><td>Description</td><td>&nbsp;" & objItem.Description & "&nbsp;&nbsp;(" & objItem.SystemName  & ")</td></tr>"
           objNewFile.WriteLine "<tr><td>NetConnectionID</td><td>&nbsp;" & objItem.NetConnectionID & "</td></tr>"
           objNewFile.WriteLine "<tr><td>PhysicalAdapter</td><td>&nbsp;" & objItem.PhysicalAdapter & "</td></tr>"
           ' objNewFile.WriteLine "<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"
         Next
         objNewFile.WriteLine "</table>"
         objNewFile.WriteLine "<br />"
      
      Next
      
      objNewFile.WriteLine "</body>"
      objNewFile.WriteLine "</html>"
      objNewFile.Close
      
      
      ' do not try opening the html file before the script finished it,
      ' wait for the popup
      Set wshShell = WScript.CreateObject("WScript.Shell")
      WshShell.Popup "html-file completed", 3, "done", 64+4096
      wscript.quit

      Optionally,
      To make the output shorter, maybe you could also list the network adapter names vertically in the first column of the table and the properties of each adapter horizontally in cells on he same row? Like in this powershell example, http://newdelhipowershellusergroup.b...n-reports.html


      /Rems

      This posting is provided "AS IS" with no warranties, and confers no rights.

      __________________

      ** Remember to give credit where credit's due **
      and leave Reputation Points for meaningful posts

      Comment


      • #4
        Re: VBS Output to html file

        Hi Rems,
        I was hoping you could pick s'thing up

        I just merged the scriptomatic WMI query and this: http://technet.microsoft.com/library/ee692829.aspx

        As soon as I managed to get it working, I wasn't too much bothered about the fine details.
        Obviously your version is much more refined so I'll start using that.

        Not bothered too much about the HTML formatting TBH, The output file is only going to be used as part of a registration process.

        Thanks for the input.
        Caesar's cipher - 3

        ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH!

        SFX JNRS FC U6 MNGR

        Comment

        Working...
        X