Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > Windows Script Host
Petri.co.il is happy to award RicklesP the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read
Notices

VBS Output to html file

VBS Output to html file

this thread has 3 replies and has been viewed 3815 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 30th March 2012, 14:40
L4ndy L4ndy is offline
Moderator
 
 Join Date: May 2006
  6 month star 12 month star
 Location: Liverpool, UK
 Posts: 2,634
 Reputation: L4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of light (541)
Default 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  
Old 30th March 2012, 17:04
L4ndy L4ndy is offline
Moderator
 
 Join Date: May 2006
  6 month star 12 month star
 Location: Liverpool, UK
 Posts: 2,634
 Reputation: L4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of light (541)
Default 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
  #3  
Old 30th March 2012, 19:54
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,406
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (944)
Default Re: VBS Output to html file

Quote:
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
  #4  
Old 3rd April 2012, 18:05
L4ndy L4ndy is offline
Moderator
 
 Join Date: May 2006
  6 month star 12 month star
 Location: Liverpool, UK
 Posts: 2,634
 Reputation: L4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of lightL4ndy is a glorious beacon of light (541)
Default 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
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect script output to log file igor7 General Scripting 2 7th December 2011 01:58
Help in editing code in multiple HTML files using a Batch file or using JS file surmar General Scripting 9 27th July 2010 07:10
Save output of a script to a file rotunnoe General Scripting 2 22nd October 2009 17:13
How to redirect output of this script to a txt file ? ganesh_bendre General Scripting 2 23rd October 2008 15:18
VBS - Trying to redirect output to text file CypherDragon General Scripting 5 29th February 2008 22:01


All times are GMT +3. The time now is 11:03.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri