Help with VBS & HTA script

thanatos05
thanatos05 used Ask the Experts™
on
Hi
I have been trying to consolidate parts of 2 VBS2 scripts I found out on the interned. The results are to output on the screen and saved as an XML when a button is pressed. I am new to scripting and have completed some online tutorials but continue to have problems with this "SMALL"  project i am trying to accomplish.

The script works as is but i want "script top" to do what "script bottom" is doing. When I select the check boxes and hit the RUN XML button, the script output (Domain) displays on the screen and creates an XML file with the output.

I want it to do this on the "script top so that particular data (Operating System: Microsoft Windows XP Home Edition ) outputs instead.

Please help!!!

<head>
<hta:application
        applicationname="PCinfoTool"
>
<script language="VBScript">
    Option Explicit
    Private objWMIService
    Private strComputer

    Function HTMLEncode(strValue)
        HTMLEncode= REplace(Replace(strValue,"<","&lt;"),">","&gt;")
    End Function
' Main procedure used to generate report. Calls other procedures that generate the HTML for each section
    Sub GenerateReport
       
        if strComputer = "" Then
            Dim objNetwork
            set objNetwork = createobject("wscript.network")
            strComputer =  objNetwork.ComputerName
   
        End If
   
        Dim objSWbemLocator
        On Error Resume Next
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
       
        OS.InnerHTML = OS_HTML
    End Sub
' Returns a HTML report for the "Operating System" section
      Function OS_HTML()
           Dim objItem, colItems
        Dim strHTML
   
        Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
        For Each objItem In colItems
        Dim strCaption
        Dim intServicePackMajor,intServicePackMinor,intTotalVisibleMemorySize
        On Error Resume Next
            strCaption = HTMLEncode(objItem.Caption)
            intServicePackMajor = objItem.ServicePackMajorVersion
            intServicePackMinor = objItem.ServicePackMinorVersion
               
            strHTML = strHTML & "<table class=""Table"">" & _
                         "<tr>" & _
                         "<th>Operating System:</th><td>" & strCaption & "</td>" & _
                         "<tr>" & _
                         "<th>Service Pack:</th><td>" & intServicePackMajor & "</td>" & _
                         "</table>"
         Next
        OS_HTML = strHTML
    End Function
</script>
<script language="VBScript">
sub mainone
    results =  results & "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbcrlf
    results =  results & "<Inventory>" & vbcrlf
        
        if OS_Info.checked then
            results =  results & "<PC_info>" & vbcrlf
            '    Get Local Login Information
            Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
            For Each objItem in colItems
                results =  results & "<Domain>" & objItem.Domain & "</Domain>" & vbcrlf
                results2 =  results2 & "Domain            :" & objItem.Domain & "<BR>"
            Next
            results =  results & "</PC_info>" & vbcrlf
        end if
    results =  results & "</Inventory>" & vbcrlf

    DataArea.InnerHTML = results2
    if xml_Info.checked then output(results)
end sub
 
Sub Output(myxml)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile("Output.xml", true)
        objFile.Write myxml
        objFile.Close
End Sub
</script>


</head>
<body OnLoad="GenerateReport">
<div id="Main" style="display:none;"></div>
<div id="OS" class="InfoSectionBody" ></div>
<hr>
<hr>
<input type="checkbox" name="OS_Info" id="OS_Info"> Domain
<input type="checkbox" name="xml_Info" id="xml_Info"> output to xml?
<input type="button" value="RUN XML" name="run_button"  onClick="mainone" />
<p><span id=DataArea>Output will be saved to Output.xml</span></p>


</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010

Commented:
Hi, thatntos05.

Sorry, but I'm lost on what the "script top" and "script bottom" that you refer to are.  Can you explain?

Author

Commented:
If you run my script there is a horizontal rule, the top is one vbs and the bottom is the second vbs within the HTA. I would like to keep both scripts but i want the output to XML to include the operating system on the top script to output on the XML.

You may want to try my script as my terminology is not that well since I am fairly new at this.
Top Expert 2010

Commented:
I did run the script and I do see the lines.  Are you saying that you want the XML to appear between those lines?
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Maybe this is an easier approach. This is the original working script. I want it to have a submit button that will capture the output of the Operating System / General section to save as XML. It connects to remote computers and I would like to capture the output.

I tried playing with the other script (script bottom) that has some  XML functions that work but i cannot get it to cork with this script.
<head>
<title></title>
<hta:application 
		applicationname="PCinfoTool" 
		scroll="yes" 
		singleinstance="no"
        windowstate="normal"
>
<style type="text/css">
body {
	margin:0px;
	background-color:#CBCBCB; /*#F6F6F6;*/
	font-family:Arial, Helvetica, sans-serif;
	font-size:14px;
	color:#595959;
}
h1 {
	font-size:24px;
	font-weight:bold;
	color:#FFFFFF;
	background-color:#2886C8;
	text-align:center;
	border-style:solid;
	border-width:thin;
	border-color:#C9E0F1;
	padding:5px;
}
h2 {
	font-size:18px;
	font-weight:bold;
}
h3 {
	font-size:16px;
	font-weight:bold;
}
a {
	color:#2886C8;
}

#Main {
	margin-left:20px;
	margin-right:20px;
}
#DisplayError {
	color:red;
	margin-left:20px;
	margin-right:20px;
}
#Footer {
	margin:20px;
	font-weight:bold;
	font-size:16px;
}
#Header {
	margin-left:20px;
	margin-right:20px;
	text-align:center;
}
.Button { 
	color: #444444; 
} 
.InfoSectionHeader {
	font-size:20px;
	font-weight:bold;
	background-color:#595959;
	color:#FFFFFF;
	text-align:center;
	padding:5px;
	margin-top:0px;
	cursor:pointer;
}
.InfoSection {
	text-align:center;
	margin-bottom:10px;
	background-color:#FFFFFF;
	border-color:#595959;
	border-style:dotted;
	border-width:1px;
}
.InfoSectionBody {
	padding:10px;
}
.Link {
	text-decoration: underline;
	cursor:pointer;
	color:#2886C8;
}
.HeaderLink {
	text-decoration: underline;
	cursor:pointer;
	color:#FFFFFF;
}
.Table {
	/*width:90%;*/
    border: 2px solid;
	border-collapse: collapse;
	border-color: #696969;
}
.Table th {
	border: 1px dotted #111111;
	border-color: #787878;
	color: #FFFFFF;
	font: bold 12pt arial, sans-serif;
	background-color: #595959; /* #787878;*/
	text-align: left;
 padding=3px;
}
.Table td {
	border: 1px dotted #111111;
	border-color: #787878;
	font: bold 10pt arial, sans-serif;
	color: #787878;
 padding=5px;
}

</style>
<script language="VBScript">

	Option Explicit
	Const bytesToMB = 1048576
    Const bytesToGB = 1073741824
    Const bytesToTB = 1099511627776
    Const adVarChar = 200
    Const adDate = 7
	Const MaxCharacters = 255
	Const adFldIsNullable = 32
	Const adInteger = 3
	Const adBigInt = 20
    Const blnConfirmKillProcess = true
	Const ADS_SECURE_AUTHENTICATION = 1
    
    Private objWMIService
    Private strComputer
    private intProcessTimerID
	
	
	
	' ***************************************
	' Kills the specified process
	' Called when "Kill Process" link is clicked in the Running Processes section
	' ***************************************
	Sub KillProcess(ByVal intProcessID, ByVal strName)
		Dim objItem, colItems
		strComputer = CurrentComputer.InnerHTML
		if blnConfirmKillProcess = True then
			if msgbox("Are you sure you want to kill the '" & strName & "' process on '" & strComputer & "'?",vbYesNo+vbExclamation,"Confirm Kill Process") = vbNo then
				exit sub
			end if
		end if
		'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		Set colItems = objWMIService.ExecQuery("Select * from Win32_Process WHERE ProcessID = '" & _
											 intProcessID & "' AND Name = '" & strName & "'")

		For Each objItem In colItems
			objItem.Terminate()
	next
	End Sub
	
	
	
	
	' ***************************************
	' Stores the sort value for "Running Processes" section in a hidden div
	' ***************************************
	Sub MapPrinter(ByVal strPath)
		Dim objNetwork
		Set objNetwork = createobject("Wscript.Network")
		objNetwork.AddWindowsPrinterConnection(strPath)
		If MsgBox("Make Printer Default?",vbYesNo+vbQuestion,"Default Printer") = vbYes Then
			objNetwork.SetDefaultPrinter strPath
		End If
	End Sub
	
	' ***************************************
	' Replace special HTML characters
	' ***************************************
	Function HTMLEncode(strValue)
		HTMLEncode= REplace(Replace(strValue,"<","&lt;"),">","&gt;")
	End Function
	
	' ***************************************
	' Convert Bytes to MB,GB or TB as appropriate
	' ***************************************
    Function ConvertToDiskUnit(ByVal value) 
        IF (value/bytesToTb) > 1 Then
            ConvertToDiskUnit = round(value / bytesToTB,1) & " TB"
        ELSEIF (value/bytesToGb) > 1 Then
            ConvertToDiskUnit = round(value / bytesToGB,1) & " GB"
        Else
            ConvertToDiskUnit = round(value / bytesToMB,1) & " MB"
        END If
    End Function
    
    	' ***************************************
	' Convert integer value to string
	' ***************************************
    Function GetMemoryType(ByVal intType)
       	Dim strType
    	Select case intType
    	Case 0
 			strType = "Unknown"
 		Case 1
 			strType = "Other"
 		Case 2
 			strType = "DRAM"
 		Case 3
 			strType = "Synchronous DRAM"
		Case 4
			strType = "Cache DRAM"
		Case 5
			strType = "EDO" 
		Case 6
		 	strType = "EDRAM" 
		Case 7
		 	strType = "VRAM"
		Case 8
		 	strType = "SRAM"
		Case 9
		  	strType = "RAM"
		Case 10
		 	strType = "ROM"
		Case 11
			strType = " Flash"
		Case 12
			strType = "EEPROM"
		Case 13
 			strType = "FEPROM"
		Case 14
		 	strType = " EPROM"
		Case 15
		 	strType = " CDRAM"
		Case 16
		  	strType = "3DRAM"
		Case 17
		 	strType = " SDRAM"
		Case 18
		 	strType = " SGRAM"
		Case 19
		 	strType = " RDRAM"
		Case 20
		 	strType = " DDR"
		Case 21
		 	strType = " DDR-2"
		Case Else
		 	strType = "Unknown"
		End Select
		GetMemoryType=strType
    End Function
    
    ' ***************************************
	' Convert Integer value to string
	' ***************************************
    Function GetMemoryFormFactor(ByVal intFormFactor)
    	Dim strFormFactor
    	Select Case intFormFactor
    	Case 0
			strFormFactor = "Unknown"
		Case 1
			strFormFactor = "Other"
		Case 2
			strFormFactor = "SIP"
		Case 3
			strFormFactor = "DIP"
		Case 4
			strFormFactor = "ZIP"
		Case 5
			strFormFactor = "SOJ"
		Case 6
			strFormFactor = "Proprietary"
		Case 7
			strFormFactor = "SIMM"
		Case 8
			strFormFactor = "DIMM"
		Case 9
			strFormFactor = "TSOP"
		Case 10
			strFormFactor = "PGA"
		Case 11
			strFormFactor = "RIMM"
		Case 12
			strFormFactor = "SODIMM"
		Case 13
			strFormFactor = "SRIMM"
		Case 14
			strFormFactor = "SMD"
		Case 15
			strFormFactor = "SSMP"
		Case 16
			strFormFactor = "QFP"
		Case 17
			strFormFactor = "TQFP"
		Case 18
			strFormFactor = "SOIC"
		Case 19
			strFormFactor = "LCC"
		Case 20
			strFormFactor = "PLCC"
		Case 21
			strFormFactor = "BGA"
		Case 22
			strFormFactor = "FPBGA"
		Case 23
			strFormFactor = "LGA"
		case Else
			strFormFactor = "Unknown"
		End Select
		GetMemoryFormFactor=strFormFactor
    End Function
    
   	' ***************************************
	' Convert date string to a more readable format
	' ***************************************
    Function FormatDate(ByVal strValue)
    	Dim strDate
    	If ISNULL(strValue) Or strValue = "" Then
    		strDate = ""
    	Else
    		strDate = Left(strValue,4) & "-" & MID(strValue,5,2) & "-" & MID(strValue,7,2) & " " & _
    				Mid(strValue,9,2) & ":" &  Mid(strValue,11,2)
    	End If
    	FormatDate = strDate
    End Function
    
	' ***************************************
	' Clear existing report data
	' ***************************************
	Sub Reset
		
		window.clearInterval(intProcessTimerID)
		Main.Style.Display = "none"
		LogicalDisk.InnerHTML=""
		PhysicalDisk.InnerHTML=""
		OS.InnerHTML =""
		DisplayError.InnerHTML=""
	End Sub
	
	' ***************************************
	' Main procedure used to generate report
	' Calls other procedures that generate the HTML for each section
	' ***************************************
	Sub GenerateReport
		Reset()
		strComputer = txtComputer.Value
		if strComputer = "" Then 
			Dim objNetwork
			set objNetwork = createobject("wscript.network")
			strComputer =  objNetwork.ComputerName
			txtComputer.Value = strComputer
		End If
		CurrentComputer.InnerHTML = strComputer
		Dim objSWbemLocator
		On Error Resume Next
		If txtUserName.Value <> "" Then
			Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
			Set objWMIService = objSWbemLocator.ConnectServer _
				(strComputer, "root\cimv2", txtUserName.Value, txtPassword.Value)
			objWMIService.Security_.ImpersonationLevel = 3
		Else
			Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		End If
		
		If Err.Number <> 0 Then
			On Error GoTo 0
			DisplayError.InnerHTML = "Error connecting to '" & strComputer & "'"
			Err.Clear
			Exit Sub
		End If
		On Error GoTo 0
		Main.Style.Display = ""
		
		LogicalDisk.InnerHTML = LogicalDisk_HTML
		PhysicalDisk.InnerHTML = PhysicalDisk_HTML
		OS.InnerHTML = OS_HTML
		
	
	End Sub
	
	    
    ' ***************************************
	' Gets computer system info to be included in the "OS / General" section
	' *************************************** 
    Sub GetComputerSystemInfo(BYRef strDNSHostName,ByRef strDomain,ByRef strDomainRole, _
    						ByRef strManufacturer,ByRef strModel,ByRef strUserName)
    	Dim objItem, colItems
		
		Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
		For Each objItem In colItems
			On Error Resume Next 
			strDNSHostName = HTMLEncode(objItem.DNSHostName)
			strDomain = HTMLEncode(objItem.Domain)
			strManufacturer = HTMLEncode(objItem.Manufacturer)
			strModel = HTMLEncode(objItem.Model)
			strUserName = HTMLEncode(objItem.UserName)
			On Error GoTo 0
			If strUserName = "" Then
				strUserName = "{not logged in}"
			End If
			Select Case objItem.DomainRole
				Case 0
				strDomainRole="Standalone Workstation"
				Case 1
				strDomainRole="Member Workstation"
				Case 2
				strDomainRole="Standalone Server"
				Case 3
				strDomainRole="Member Server"
				Case 4
				strDomainRole="Backup Domain Controller"
				Case 5
				strDomainRole="Primary Domain Controller"
				Case Else
				strDomainRole = "Unknown (" & strDomainRole & ")"
			End Select
		Next
    End Sub
    
    ' ***************************************
	' Returns a HTML report for the "Operating System/General" section
	' ***************************************  
    Function OS_HTML()
    
    	Dim objItem, colItems
		Dim strHTML
		Dim strDNSHostName,strDomain,strDomainRole,strManufacturer,strModel,strUserName
		GetComputerSystemInfo strDNSHostName,strDomain,strDomainRole,strManufacturer,strModel,strUserName
		
		Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
		
		strHTML = "<h3>Current User: " & strUserName & "</h3>"
		
		For Each objItem In colItems
			Dim strComputerRole
			Dim strCaption,strBuildNumber,strInstallDate,strBootDate
			Dim intServicePackMajor,intServicePackMinor,intTotalVisibleMemorySize
			Dim intFreePhysicalMemory,intTotalVirtualMemorySize,intFreeVirtualMemory
			On Error Resume Next
			strCaption = HTMLEncode(objItem.Caption)
			strBuildNumber = HTMLEncode(objItem.BuildNumber)
			intServicePackMajor = objItem.ServicePackMajorVersion
			intServicePackMinor = objItem.ServicePackMinorVersion
			intTotalVisibleMemorySize = objItem.TotalVisibleMemorySize
			intFreePhysicalMemory = objItem.FreePhysicalMemory
			intFreeVirtualMemory =  objItem.FreeVirtualMemory
			intTotalVirtualMemorySize = objItem.TotalVirtualMemorySize
			strInstallDate = FormatDate(objItem.InstallDate)
			strBootDate = FormatDate(objItem.LastBootUpTime)
			On Error GoTo 0
						
			strHTML = strHTML & "<table class=""Table"">" & _
					 	"<tr>" & _
					 	"<th>Operating System:</th><td>" & strCaption & "</td>" & _
					 	"<th>Build Number:</th><td>" & strBuildNumber & "</td>" & _
					 	"</tr><tr>" & _
					 	"<th>Service Pack:</th><td>" & intServicePackMajor & "." &  intServicePackMinor & "</td>" & _
					 	"<th>Role:</th><td>" & strDomainRole & "</td>" & _
					 	"</tr><tr>" & _
					 	"<th>DNS Host Name:</th><td>" & strDNSHostName & "</td>" & _
					 	"<th>Domain:</th><td>" & strDomain & "</td>" & _
					 	"</tr><tr>" & _
					 	"<th>Manufacturer:</th><td>" & strManufacturer & "</td>" & _
					 	"<th>Model:</th><td>" & strModel & "</td>" & _
					 	"</tr><tr>" & _
					 	"<th>Total Physical Memory:</th><td>" & intTotalVisibleMemorySize & "KB</td>" & _
					 	"<th>Free Physical Memory:</th><td>" & intFreePhysicalMemory  & "KB</td>" & _
					 	"</tr><tr>" & _
					 	"<th>Total Virtual Memory:</th><td>" & intTotalVirtualMemorySize & "KB</td>" & _
					 	"<th>Free Virtual Memory:</th><td>" & intFreeVirtualMemory & "KB</td>" & _
					 	"</tr><tr>" & _
					 	"<th>Install Date:</th><td>" & strInstallDate & "</td>" & _
					 	"<th>Last BootUp Time:</th><td>" & strBootDate & "</td>" & _
					 	"</tr>" & _
					 	"</table>"
					 	
			Exit For
		Next
		
		OS_HTML = strHTML
		
    End Function
    
	' ***************************************
	' Get the number of memory slots and memory arrays
	' for the memory section
	' ***************************************
    Function GetMemoryArrayInfo(ByRef intSlots,ByRef intArrays)
    	Dim objItem, colItems
		intSlots = 0
		intArrays = 0
    	Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemoryArray WHERE Use=3")
    	
    	For Each objItem In colItems
    		intSlots = intSlots + objItem.MemoryDevices
    		intArrays = intArrays + 1
    	Next
    End Function
    	
	
    
    ' ***************************************
	' Returns a HTML report for the "Physical Disk" section
	' ***************************************  
    Function PhysicalDisk_HTML()
    	Dim objItem, colItems
		Dim strHTML
		
		Set colItems = objWMIService.ExecQuery("Select * from Win32_DiskDrive")

		strHTML = "<table class=""Table""><tr><th>Caption</th><th>Manufacturer</th>" & _
				"<th>Model</th><th>Size</th><th>Serial</th><th>Media Type</th><th>#Partitions</th><th>DeviceID</th><th>Firmware</th><th>Interface</th></tr>"

		For Each objItem in colItems
			Dim intSize,intPartitions
			Dim strSize,strCaption,strManufacturer,strModel,strMediaType
			Dim strDeviceID,strFirmwareRevision,strInterfaceType, strSerialNumber
			intSize = objItem.Size
			If IsNumeric(intSize) = False Then
				intSize = 0
			End If
			On Error Resume Next
			strCaption= HTMLEncode(objItem.Caption) 
			strSize = ConvertToDiskUnit(intSize)
			strSerialNumber = HTMLEncode(objItem.SerialNumber)
			strMediaType = HTMLEncode(objItem.MediaType)
			intPartitions = HTMLEncode(objItem.Partitions)
			strDeviceID = HTMLEncode(objItem.DeviceID)
			strFirmwareRevision = HTMLEncode(objItem.FirmwareRevision)
			strInterfaceType = HTMLEncode(objItem.InterfaceType)
			strModel = HTMLEncode(objItem.Model)
			strManufacturer = HTMLEncode(objItem.Manufacturer)
			On Error GoTo 0
		
			strHTML = strHTML & "<tr><td>" & strCaption & "</td>" & _
								"<td>" & strManufacturer & "</td>" & _
								"<td>" & strModel & "</td>" & _
								"<td>" & strSize & "</td>" & _
								"<td>" & strSerialNumber & "</td>" & _
								"<td>" & strMediaType & "</td>" & _
								"<td>" & intPartitions & "</td>" & _
								"<td>" & strDeviceID & "</td>" & _
								"<td>" & strFirmwareRevision & "</td>" & _
								"<td>" & strInterfaceType & "</td>" & _
								"</tr>"
		Next
		strHTML = strHTML & "</table>"
		
		PhysicalDisk_HTML=strHTML
    	
    End Function

	' ***************************************
	' Returns a HTML report for the "Logical Disk" section
	' ***************************************  
	Function LogicalDisk_HTML()

		Dim objItem, colItems
		Dim strDriveType, strDiskSize, strHTML
		
		Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk WHERE DriveType = 3")

		strHTML = "<table class=""Table""><tr><th>Drive</th><th>Name</th><th>File System</th><th>Size</th><th>Used</th><th>Free</th><th>Free(%)</th></tr>"

		For Each objItem in colItems
	
			Dim pctFreeSpace,strFreeSpace,strusedSpace,strName,strFileSystem,strVolumeName
			Dim intFreeSpace, intSize
			On Error Resume Next
			intFreeSpace = objItem.FreeSpace
			intSize = objItem.Size
			If ISNUMERIC(intFreeSpace) = False Then
				intFreeSpace=0
			End If
			If IsNumeric(intSize) = False Then
				intSize = 0
			End If
			If objItem.FreeSpace > 0 Then
				pctFreeSpace = round(((intFreeSpace / intSize) * 100),0)
			Else
				pctFreeSpace=0
			End If
			strDiskSize = ConvertToDiskUnit(intSize) 
			strFreeSpace = ConvertToDiskUnit(intFreeSpace)
			strUsedSpace = ConvertToDiskUnit(intSize-intFreeSpace)
			strName = HTMLEncode(objItem.Name)
			strVolumeName = HTMLEncode(objItem.VolumeName)
			strFileSystem = HTMLEncode(objItem.FileSystem)
			On Error GoTo 0

			dim strChart 
			strChart = "<div width=100%;""><span style=""padding:0px;margin:0px;width=" & 100-pctFreeSpace & _
				"%;background-color:blue;"">&nbsp;</span><span style=""padding:0px;margin:0px;width=" & pctFreeSpace & _
				"%;background-color:#FF00FF;"">&nbsp;</span></div>"

			strHTML = strHTML & "<tr><td>" & strName & "</td><td>" & _
					strVolumeName & "</td><td>" & strFileSystem & "</td><td>" & _
					strDiskSize & "</td><td>" & strUsedSpace & "</td><td>" & _
					strFreeSpace & "</td><td>" &  pctFreeSpace & "%</td></tr>" & _
					"<tr><td colspan=""7"">" & strChart & "</td></tr>"

		Next
	
		strHTML = strHTML + "</table></br>"

		LogicalDisk_HTML = strHTML
	
	End Function
	
</script>

<script type="text/javascript">
	/* Toggle expand/collapse state for specified section */
	function toggleDisplay(obj) {
		var el = document.getElementById(obj);
		if ( el.style.display != 'none' ) {
			el.style.display = 'none';
		}
		else {
			el.style.display = '';
		}
	}
	/* Toggle expand/collapse state for all sections */
	function toggleAll() {
		var el = document.getElementById("OS");
		var display = ''
		if ( el.style.display != 'none' ) {
			display = 'none';
		}
		el.style.display = display;
		el.style.display = display;
		el = document.getElementById("LogicalDisk");
		el.style.display = display;
		el = document.getElementById("PhysicalDisk");
		
	}
	
</script>

</head>
<body OnLoad="GenerateReport">
<h1></h1>
<div id="Header" style="padding-bottom:0px;margin-bottom:0px;">
	<table style="font-weight:bold;"><tr><td>UserName:</td><td><input id="txtUserName"></input></td><td style="font-size:8px;">(Optional)</td><tr>
	<tr><td>Password:</td><td><input type="password" id="txtPassword"></input></td><td style="font-size:8px;">(Optional)</td></tr>
	<tr><td>Computer:</td><td><input id="txtComputer"></input></td>
	<td colspan="2">  <input class="Button" style="font-weight:bold;" onClick="GenerateReport()" type="submit" value="Generate Report">
    <td colspan="2">  <input class="Button" style="font-weight:bold;" onClick="window.print()" type="submit" value="Print Report">
   

  </input>
  </td></tr>
  </table>
 </div>
 
  <div id="Main" style="display:none;">
  <div id="CurrentComputer" style="display:none"></div>
  <div style="text-align:right;">
  <span class="Link" style="font-weight:bold;" onclick="javascript:toggleAll();">Expand/Collapse All</span>
  </div>
  <div class="InfoSection">
    <div onClick="javascript:toggleDisplay('OS');"  class="InfoSectionHeader">Operating System / General</div>
    <div id="OS" class="InfoSectionBody" ></div>
  </div>
  </div>
 
  </div>
  <div class="InfoSection">
    <div onClick="javascript:toggleDisplay('LogicalDisk');"  class="InfoSectionHeader">Logical Disk</div>
    <div id="LogicalDisk" class="InfoSectionBody"></div>
  </div>
  <div class="InfoSection">
    <div onClick="javascript:toggleDisplay('PhysicalDisk');" class="InfoSectionHeader">Physical Disk</div>
    <div id="PhysicalDisk" class="InfoSectionBody"></div>
  </div>
    </div>
    </div>
  </div>
</div>
<div id="DisplayError"></div>
<div id="Footer">
<hr/>
    <div style="clear:both;"></div>
    <div style="text-align:center;font-size:20px;font-weight:bold"></div>
</div>

<input type="text" name="strcomputers" size="1" style="width: 1px; height: 1px"/><br>
<input type="text" name="strUser" size="1" style="width: 1px; height: 1px"/><br>
<input type="text" name="strPassword" size="1" style="width: 1px; height: 1px"/><BR>
</div>

</body>
</html>

Open in new window

Author

Commented:
no, I do not see the Operating System and service pack in the display or xml file that saves.  I only see the Domain field
Top Expert 2010

Commented:
Got it.  Your test for the checkbox is what's not working.  I've fixed it in the version below.  Replace the sub named mainone with this version.
sub mainone 
	Set objCheckbox = document.getElementById("OS_Info")
    results =  results & "<?xml version=" & Chr(34) & "1.0" & Chr(34) & "?>" & vbcrlf 
    results =  results & "<Inventory>" & vbcrlf 
        if objCheckbox.Value = "on" then 
        	MsgBox "Made it"
            results =  results & "<PC_info>" & vbcrlf 
            '    Get Local Login Information 
            Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48) 
            For Each objItem in colItems 
                results =  results & "<Domain>" & objItem.Domain & "</Domain>" & vbcrlf 
                results2 =  results2 & "Domain            :" & objItem.Domain & "<BR>" 
            Next 
            results =  results & "</PC_info>" & vbcrlf 
        end if 
    results =  results & "</Inventory>" & vbcrlf 
 
    DataArea.InnerHTML = results2 
    if xml_Info.checked then output(results) 
end sub

Open in new window

Author

Commented:
Not quite yet. I apologize for confusing you. Hou can I get the script below to OUTPUT its results under the Horizontal Rule and at the same time create an  OUTPUT.XML file when clicking on a button.

 
<head>
<hta:application 
		applicationname="PCinfoTool" 
>

<script language="VBScript">
	Option Explicit
    Private objWMIService
    Private strComputer

	Function HTMLEncode(strValue)
		HTMLEncode= REplace(Replace(strValue,"<","&lt;"),">","&gt;")
	End Function
' Main procedure used to generate report. Calls other procedures that generate the HTML for each section
	Sub GenerateReport
		
		if strComputer = "" Then 
			Dim objNetwork
			set objNetwork = createobject("wscript.network")
			strComputer =  objNetwork.ComputerName
	
		End If
	
		Dim objSWbemLocator
		On Error Resume Next
		Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
		
		OS.InnerHTML = OS_HTML
	End Sub
' Returns a HTML report for the "Operating System" section
      Function OS_HTML()
       	Dim objItem, colItems
		Dim strHTML
	
		Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
		For Each objItem In colItems
		Dim strCaption
		Dim intServicePackMajor,intServicePackMinor,intTotalVisibleMemorySize
		On Error Resume Next
			strCaption = HTMLEncode(objItem.Caption)
			intServicePackMajor = objItem.ServicePackMajorVersion
						
			strHTML = strHTML & "<table class=""Table"">" & _
					 	"<tr>" & _
					 	"<th>Operating System:</th><td>" & strCaption & "</td>" & _
					 	"<tr>" & _
					 	"<th>Service Pack:</th><td>" & intServicePackMajor & "</td>" & _
					 	"</table>"
	 	Next
		OS_HTML = strHTML
    End Function
</script>
</head>
<body OnLoad="GenerateReport">
<div id="Main" style="display:none;"></div>
<div id="OS" class="InfoSectionBody" ></div>
<hr>
<hr>
</body>
</html>

Open in new window

Author

Commented:
The scripts that I put on here all work fine. The problem is that they do not include the OPERATING SYSTEM & SERVICE PACK when it creates this XML. All i get is:

<?xml version="1.0"?>
<Inventory>
    <PC_info>
        <Domain>MSHOME</Domain>
    </PC_info>
</Inventory>

Author

Commented:
Don't give up on me :-( i posted a picture that i hope helps define what I am trying to accomplish. That is what i am trying to do with the operating system and service pack for the script i posted.
Script.JPG

Author

Commented:
Here is another picture with the script we have been playing with.
Script2.JPG
Top Expert 2010

Commented:
Sorry, I'm more confused now than I was before.  The first code you posted didn't write anything to the XML file except

<?xml version="1.0"?>
<Inventory>

 After I changed the way the checkbox is tested it wrote

<?xml version="1.0"?>
<Inventory>
    <PC_info>
        <Domain>MSHOME</Domain>
    </PC_info>
</Inventory>

You then say that the script worked ok to begin with except that it doesn't write the operating system and service pack.  If that's the question, then the answer is to use the same technique you used on lines 59 to 67 of the code in your original post.  You appear to have code that creates an XML file and you have code that returns the OS info you want to write to the XML file.  I guess I just don't understand the issue.
Gave up on this so I will accept solution

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial