![]() |
|
|
|||||||
| Petri.co.il is happy to award auglan the title of Most Valuable Member !!! |
| Register | Calendar |
Search |
Today's Posts |
Mark Forums Read |
| Notices |
|
|
VBS Output to html filethis thread has 3 replies and has been viewed 1733 times
|
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||||||||
|
|||||||||
|
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
__________________
Caesar's cipher - 3 ZKHQ BRX HYHQWXDOOB GHFLSKHU WKLV BRX ZLOO UHDOLVH LW ZDV D ZDVWH RI WLPH! SFX JNRS FC U6 MNGR |
|
#2
|
|||||||||
|
|||||||||
|
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> 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> " & objItem.Description & "</td></tr>"
objNewFile.WriteLine "<tr><td>MACAddress</td><td> " & objItem.MACAddress & "</td></tr>"
objNewFile.WriteLine "<tr><td>Name</td><td> " & objItem.Name & "</td></tr>"
objNewFile.WriteLine "<tr><td>NetConnectionID</td><td> " & objItem.NetConnectionID & "</td></tr>"
objNewFile.WriteLine "<tr><td>PhysicalAdapter</td><td> " & objItem.PhysicalAdapter & "</td></tr>"
objNewFile.WriteLine "<tr><td>SystemName</td><td> " & 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
|
||||||||||
|
||||||||||
|
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> 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: " & 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> " & objItem.Name & "</td></tr>"
objNewFile.WriteLine "<tr><td>MACAddress</td><td> " & objItem.MACAddress & "</td></tr>"
objNewFile.WriteLine "<tr><td>Description</td><td> " & objItem.Description & " (" & objItem.SystemName & ")</td></tr>"
objNewFile.WriteLine "<tr><td>NetConnectionID</td><td> " & objItem.NetConnectionID & "</td></tr>"
objNewFile.WriteLine "<tr><td>PhysicalAdapter</td><td> " & objItem.PhysicalAdapter & "</td></tr>"
' objNewFile.WriteLine "<tr><td> </td><td> </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
|
|||||||||
|
|||||||||
|
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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |