Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTA - reload certain fields

Status
Not open for further replies.

cluM09

Technical User
May 15, 2004
127
US
Hello,

I have an HTA script that I used to query some information from certain servers for hardware information. I want to reload certain fields on the form, but I don't know how to do it. I have a reload sub routine, but it will reload the whole page. The code is listed below:

Sub RunRefresh
Location.Reload(True)
End Sub

My question is how can I refresh only certain fields on the html page?
 
Hi clum09,

I think this depends upon how you have defined the fields in the HTA.

I have certain boxes defined in a small calculator I wrote for a friend. If necessary I can leave out some fields from the reload sub & it will ignore them....

Do you have an example of your code, or alternatively, I can post the one I wrote if you like so you can see how I wrote my clearwindow sub.

Rgds
Woolsdog

Keyboard Not Detected.....
Press F1 to Continue.
:}
 
Hi Woolsdog,

Thank you for the response! The script I wrote is used to check for the hardware information of the server, such as manufacturer, serial number, model number, CPU type and speed, number of CPUs and total physical RAM. The code is listed below:

-----------------------------------------------------------

<html>

<head>

<title>System Hardware Information</title>

<HTA:APPLICATION
BORDER="thin"
BORDERSTYLE="normal"
CAPTION="yes"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
SCROLL="no"
SHOWINTASKBAR="no"
SYSMENU="yes"
WINDOWSTATE="normal" />

</head>

<style>
BODY
{
background-color: buttonface;
font-family: Helvetica;
font-size: 8pt;
margin-top: 15px;
margin-left: 8px;
margin-right: 8px;
margin-bottom: 3px;
}

textarea
{
font-family: Helvetica;
font-size: 10pt;
}

BUTTON
{
font-family: Arial;
font-size: 8pt;
width: 50px;
}
BUTTON.long
{
width: 75px;
{

</style>

<script language="VBScript">

Sub Window_Onload
self.Focus()
self.ResizeTo 330,400
self.moveTo 380,240
DomainOption(0).Checked = True
strDomain = "TEXAS"
strComputerName.focus
End Sub

'Refreshes the HTA page, which includes re-running any Windows_Onload code

Sub RunRefresh
Location.Reload(True)
End Sub

Sub SelectDomain
If DomainOption(1).Checked Then
strDomain = "STAGING"
End If
If DomainOption(2).Checked Then
strDomain = "TVNEXNET"
End If
End Sub

Sub RunScript

'set user credential to access the computer.
strUser = strDomain & "\" & strUserID.value
MyPassword = strPassword.value

Const MB_OK = 0
Const MB_ICONSTOP = 16

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objShell = CreateObject("Wscript.Shell")
Set objNetwork = CreateObject("WScript.Network")
strLComputer = objNetwork.ComputerName

'Set proper computer location for the WMI query.
strComputer = strComputerName.value
Select Case UCase(strComputer)
Case ""
strComputer = strLComputer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Case strLComputer
strComputer = strLComputer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Case Else
If strUserID.value = Empty Then 'Display a message for user name input.
nMsgType = MB_OK Or MB_ICONSTOP
objShell.Popup "Please enter your user name!" & Space(5), 0, "User Name Requirement", nMsgType
Exit Sub
End If
If MyPassword = Empty Then 'Display a message for the password input.
nMsgType = MB_OK + MB_ICONSTOP
objShell.Popup "Please enter your password!" & Space(5), 0, "Password Requirement", nMsgType
Exit Sub
End If
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root/cimv2", strUser, MyPassword)
objWMIService.Security_.impersonationlevel = 3
If Err.number = 424 Then
nMsgType = MB_OK + MB_ICONSTOP
objShell.Popup "Error: Access Error." & Space(5) & vbCrLf _
& vbCrLf _
& "Please check your input information and try again." & Space(5), 0, "Access Error", nMsgType
Exit Sub
End If
On Error Goto 0
End Select
'Query for the hardware information.
Set colItems = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objItem In colItems
Msg.value = Msg.value & "Manufacturer: " & objItem.Manufacturer & vbCrLf
Msg.value = Msg.value & "Serial Number: " & objItem.SerialNumber & vbCrLf
Next

Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
Msg.value = Msg.value & "Model: " & objItem.Name & vbCrLf
' Msg.value = Msg.value & "Serial Number: " & objItem.IdentifyingNumber & vbCrLf
Next

Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objItem in colItems
CPUSpeed = objItem.CurrentClockSpeed
CPUType = Trim(objItem.Name)
Next
CPUType = Replace(CPUType, "(R)", "")
If InStr(CPUType, "Xeon(TM)") > 0 Then
CPUType = Replace(CPUType, "(TM)", "")
strCPUSpeed = Trim(Right(CPUType, 7))
CPUnSpeed = Split(CPUType, " ")(0) & " " & Split(CPUType, " ")(1) & " " & strCPUSpeed
ElseIf InStr(CPUType, "Pentium") > 0 Then
strCPUSpeed = Trim(Right(CPUType, 7))
If CPUSpeed < 1000 Then strCPUSpeed = CPUSpeed & "MHz"
CPUnSpeed = Split(CPUType, " ")(0) & " " & Split(CPUType, " ")(1) & " " & Split(CPUType, " ")(2) & " " & strCPUSpeed
End if
'Get physical RAM
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
PhysRAM = objItem.TotalPhysicalMemory
CPUCount = objItem.NumberOfProcessors
Next
PhysRAM = FormatNumber(PhysRAM/1046856,0,GroupDigits)

Msg.Value = Msg.Value & "CPU/Speed: " & CPUnSpeed & vbCrLf
Msg.Value = Msg.Value & "Number of CPUs: " & CPUCount & vbCrLf
Msg.Value = Msg.Value & "Physical RAM (MB): " & PhysRAM & vbCrLf

End Sub

</script>

<body>

&nbsp;&nbsp;<b><font size="2" face="Arial">Computer Name:</b></b>&nbsp;<input type="text" name="strComputerName" size="18" font size="2" face="Arial"><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><b><font size="2" face="Arial">User Name:</b>&nbsp;<input type="text" name="strUserID" size="12" font size="2" face="Arial"><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font><b><font size="2" face="Arial">Password: </b><input type="password" name="strPassword" size="12"><font size="2"></font>

<p align="left"></font>&nbsp;&nbsp;<b><font size="2" face="Arial">Please select a domain below:</b><BR>
</font>&nbsp;<input type="radio" name="DomainOption" value="1">TEXAS&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="DomainOption" value="2">STAGING&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="DomainOption" value="3">TVNEXNET<BR></p>

<p align="center"><input id=runbutton class="button" type="button" value=" OK " name="run_button" onClick="RunScript"></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp<input type="button" value="Refresh" name="B0" onclick=RunRefresh>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="Cancel" name="B1" onclick=self.close()>
<p align="center"><b><font size="2" face=Arial">Hardware Information</b><BR><textarea rows="7" name="Msg" READONLY cols="45" style="text-align: left"></textarea></p>

</body>

</html>

-----------------------------------------------------------

I want to refresh only the Computer Name field and the Hardware Information field, and I want to keep the User Name and Password fields intact.

Thanks you for your help.

CluM09
 
Hi clum09,

dead easy,
simply change your reload sub to the following:

Sub RunRefresh
strComputerName.value = ""
Msg.Value = ""
End Sub

If you wish to add another button for reloading the whole
thing then you could do that too....

Enjoy
Woolsdog

Keyboard Not Detected.....
Press F1 to Continue.
:}
 
Woolsdog,

Thank you so much for your help! It works great!

Another thing that I have just thought of is I would like to have the characters of the computer name field to be converted to upper case characters as I type the computer name into the field or have the characters be converted to upper case after I tab the cursor onto the next field.

Is it possible to do that?

Thanks again!

CluM09
 
Have a look at the UCase function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV,

Thank you for the response!

I understand that the UCase function will convert string characters to upper case, but what I want is the DISPLAY of the computer name field to be upper case during the time when I type it, not just the value after it was typed behind the display. I am sorry that I did not make it clear in my original question.

CluM09
 
cluM09 -

For the display, as the user is typing, try a style... text-transform:uppercase

strebor
 
<input type="text" name="strComputerName" size="18" font size="2" face="Arial" style="text-transform:uppercase">

strebor
 
strebor,

Thank you for the response!

Yes, this is what I am looking for. It works great!

Thanks agagin for help!

CluM09
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top