Question : HTA Dynamic Drop Down List

I need some help on creating an entry form where I have two drop down menus. The first one shows my list of available servers with print queues, and this list is a static list. The second drop down list needs to be dynamic, showing the print queues available on each server I pick from the server list. If I pick Server 1, the second drop down list will automatic populate the list of queues on Server 1. If I pick Server 2, the second drop down list will show the list of the queues on Server 2, and so on. I have no problem on querying the servers and creating the list. My problem is to associate this list with the second drop down menu box. This is the code I was able to write so far. Thanks for your help.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
<head>
<title>HTA PrinterList</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Server Print List"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">
	Sub Printers
		Dim strComputer, strHTML, PrinterName
		Const HKEY_LOCAL_MACHINE = &H80000002
		strComputer = PServer.Value
		Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		Set objReg = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
		On Error Resume Next
		Set colPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
		For Each objprinter In colPrinters
			strHTML = strHTML & (ucase(objprinter.deviceID))
		Next
		PrintList.InnerHTML = strHTML
	End Sub
	
	Sub QName
		PrinterName=(ucase(QueueName.Value))
		msgbox(PrinterName)
	End Sub
</script>

<body>
Server Name:
<select size="1" name="PServer" onChange="Printers">
<option value="NONE">Select Print Server #1</option>
<option value="SERVER1">Server1</option>
<option value="SERVER2">Server2</option>
<option value="SERVER3">Server3</option>
<option value="SERVER4">Server4</option>
<option value="SERVER5">Server5</option>
</select>
<br>
Printer Name:
<select size="1" name="QueueName" onChange="QName">
<span id = "PrintList"></span>
</select>

</body>

Answer : HTA Dynamic Drop Down List

Sure you can, but this involves reading the list into a disconnected recordset, then sorting it, and populating the list box.  I have provided this for you.

Also, I'm looking at the output when you select a queue, and it just echos the queuename.  I assume you will end up using this as a method of connecting to the print queue, so we should probably add the *share name* to the underlying *value* of each entry, so that you can use that for AddPrinterConnection method.

Let me know if that's the track you want to take, and I can help you with that.

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
<head>
<title>HTA PrinterList</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Server Print List"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">
	Sub Printers
		Dim strComputer, strHTML, PrinterName
		Const HKEY_LOCAL_MACHINE = &H80000002
		strComputer = PServer.Value
		Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
		Set objReg = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
		On Error Resume Next
		Set colPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
		ClearOptions "QueueName"
		Const adVarChar = 200
		Const MaxCharacters = 255
		Set rstList = CreateObject("ADOR.Recordset")
		rstList.Fields.Append "QueueName", adVarChar, MaxCharacters
		rstList.Open
		For Each objprinter In colPrinters
			strPrinter = objPrinter.DeviceID
		    rstList.AddNew
		    rstList("QueueName") = strPrinter
		    rstList.Update
		Next
		rstList.Sort = "QueueName"
		rstList.MoveFirst
		While Not rstList.EOF
			AddOption "QueueName", rstList("QueueName"), rstList("QueueName")
			strHTML = strHTML & (UCase(rstList("QueueName")))
			rstList.MoveNext
		Wend
		PrintList.InnerHTML = strHTML
		rstList.Close
		Set rstList = Nothing
	End Sub

	Sub AddOption(elem_id,myText,myValue)
		Set elem=document.getElementById(elem_id)
		Set objNewOption = document.createElement("OPTION")
		objNewOption.Text = myText
		objNewOption.value = myValue
		elem.options.Add(objNewOption)
	End Sub

	Sub ClearOptions(elem_id)
		Set elem=document.getElementById(elem_id)
		'elem.options.length=1
		For intListProgress = 1 To elem.options.Length
			elem.Remove 0
		Next
	End Sub

	Sub QName
		PrinterName=(ucase(QueueName.Value))
		msgbox(PrinterName)
	End Sub
</script>

<body>
Server Name:
<select size="1" name="PServer" onChange="Printers">
<option value="NONE">Select Print Server #1</option>
<option value="SERVER1">Server1</option>
<option value="SERVER2">Server2</option>
<option value="SERVER3">Server3</option>
<option value="SERVER4">Server4</option>
<option value="SERVER5">Server5</option>
</select>
<br>
Printer Name:
<select size="1" name="QueueName" onChange="QName">
<span id = "PrintList"></span>
</select>

</body>
Random Solutions  
 
programming4us programming4us