VBS Output to html file

Home Forums Scripting Windows Script Host VBS Output to html file

This topic contains 3 replies, has 2 voices, and was last updated by Avatar L4ndy 7 years, 5 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Avatar
    L4ndy
    Member
    #158280

    Hi,
    I have got the following script. How would I tweak it to save the output to an html file?

    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 & “rootCIMV2”)
    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
    [/CODE]

    Thanks[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 & “rootCIMV2”)
    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
    [/CODE]

    Thanks

    Avatar
    L4ndy
    Member
    #277146

    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.

    On Error Resume Next
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    Set objFS = CreateObject(“Scripting.FileSystemObject”)
    Set objNewFile = objFS.CreateTextFile(“C:GetMac.htm”)
    objNewFile.WriteLine “”
    objNewFile.WriteLine “”
    objNewFile.WriteLine “UAG Client information
    objNewFile.WriteLine “”
    objNewFile.WriteLine “”
    objNewFile.WriteLine “

    UAG Client Information — Date: ” & Now() & _

    ” & vbCrLf
    objNewFile.WriteLine “table {font-size: 10pt; font-family: arial;}th {background-color: buttonface; font-decoration: bold;}

    arrComputers = Array(“localhost”)
    For Each strComputer In arrComputers

    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_NetworkAdapter”, “WQL”, _
    wbemFlagReturnImmediately + wbemFlagForwardOnly)
    For Each objItem In colItems

    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    Next
    Next
    objNewFile.WriteLine “

    Property Value
    Computer  localhost
    Description  ” & objItem.Description & “
    MACAddress  ” & objItem.MACAddress & “
    Name  ” & objItem.Name & “
    NetConnectionID  ” & objItem.NetConnectionID & “
    PhysicalAdapter  ” & objItem.PhysicalAdapter & “
    SystemName  ” & objItem.SystemName & “


    objNewFile.WriteLine “”
    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
    [/CODE][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 “”
    objNewFile.WriteLine “”
    objNewFile.WriteLine “UAG Client information
    objNewFile.WriteLine “”
    objNewFile.WriteLine “”
    objNewFile.WriteLine “

    UAG Client Information — Date: ” & Now() & _

    ” & vbCrLf
    objNewFile.WriteLine “table {font-size: 10pt; font-family: arial;}th {background-color: buttonface; font-decoration: bold;}

    arrComputers = Array(“localhost”)
    For Each strComputer In arrComputers

    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_NetworkAdapter”, “WQL”, _
    wbemFlagReturnImmediately + wbemFlagForwardOnly)
    For Each objItem In colItems

    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    Next
    Next
    objNewFile.WriteLine “

    Property Value
    Computer  localhost
    Description  ” & objItem.Description & “
    MACAddress  ” & objItem.MACAddress & “
    Name  ” & objItem.Name & “
    NetConnectionID  ” & objItem.NetConnectionID & “
    PhysicalAdapter  ” & objItem.PhysicalAdapter & “
    SystemName  ” & objItem.SystemName & “


    objNewFile.WriteLine “”
    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
    [/CODE]

    Rems
    Rems
    Moderator
    #228175

    Re: VBS Output to html file

    L4ndy;256306 wrote:
    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,

    Computer  localhost


    and this is before the first For-next statement.

    In the sample below I also added the html 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 = “”
    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& “”

    objNewFile.WriteLine “”
    objNewFile.WriteLine “”
    objNewFile.WriteLine “UAG Client information
    objNewFile.WriteLine a & “”
    objNewFile.WriteLine “

    UAG Client Information — Date: ” _
    & Now() & “

    arrComputers = Array(“localhost”)

    For Each strComputer In arrComputers

    objNewFile.WriteLine “Computer: ” & strComputer & “

    objNewFile.WriteLine “


    objNewFile.WriteLine “

    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootCIMV2”)
    Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_NetworkAdapter”, “WQL”, _
    wbemFlagReturnImmediately + wbemFlagForwardOnly)

    For Each objItem In colItems
    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    objNewFile.WriteLine “


    ‘ objNewFile.WriteLine “


    Next
    objNewFile.WriteLine “

    Property Value
    Name  ” & objItem.Name & “
    MACAddress  ” & objItem.MACAddress & “
    Description  ” & objItem.Description & ”  (” & objItem.SystemName & “)
    NetConnectionID  ” & objItem.NetConnectionID & “
    PhysicalAdapter  ” & objItem.PhysicalAdapter & “
       


    objNewFile.WriteLine “

    Next

    objNewFile.WriteLine “”
    objNewFile.WriteLine “”
    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.blogspot.com/2011/10/generate-system-information-reports.html

    /Rems

    Avatar
    L4ndy
    Member
    #277148

    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.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.