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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a selection list in an HTA

Status
Not open for further replies.

PPettit

IS-IT--Management
Sep 13, 2003
511
US
I'm trying to create an HTA that will move users from one group to another. I can move all of the users without any problem, but I can't figure out how to handle specific users. I have a feeling that my handling of the select list is my primary issue at this point. I can build the list, but I'm not sure how to send the selections back to a subroutine. Once I figure that out, I can start working on the sub used to move them.

Can anyone give me a nudge in the right direction?

This is what I have so far:
Code:
<head>
<title>Terminal Server Access Control</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Allow or deny Terminal Server access"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="maximize"
>
<style type="text/css">
       #AllowedColumn {
         border: 1px solid black;
         float:left;
         height: auto;
         overflow: auto;
         padding:10px;""
         width: 40%;
         }
       #AllowedColumn h2 {color:green;}
       #AllowedDiv {
         border: 0px solid black;
         float:left;
         height: auto;
         overflow: auto;
         padding:10px;
         width: auto;
         }
       #DataArea {
         padding:10px;
         }
       #DeniedColumn {
         border: 1px solid black;
         float:left;
         height: auto;
         overflow: auto;
         padding:10px;
         width: 40%;
         }
       #DeniedColumn h2 {color:red;}
       #DeniedDiv {
         border: 0px solid black;
         float:left;
         height: auto;
         overflow: auto;
         padding:10px;
         width: auto;
         }
       #CenterDiv {
         border: 0px solid black;
         float:left;
         width: 10%;
         height: auto;
         overflow: auto;
         padding-top:100px;
         }
</style>
</head>

<script language="VBScript">
Option Explicit
Dim AllowGroup,arrayAllowed,arrayDenied,DenyGroup,strAllowList,strDenyList,strUser,User,UserName

Set AllowGroup = GetObject("WinNT://" & "Accounting" & "/" & "V2 Users" & ",group")
Set DenyGroup = GetObject("WinNT://" & "Accounting" & "/" & "Deny TS Logon" & ",group") 
Set arrayAllowed = CreateObject( "System.Collections.ArrayList" )
Set arrayDenied = CreateObject( "System.Collections.ArrayList" )

	Sub Allow_TSLogon			
			For Each UserName in DenyGroup.Members
				Set User = GetObject("WinNT://" & "Accounting" & "/" & UserName.Name & ",user")
			'###Remove from "Deny Ts Logon" group###
        DenyGroup.Remove(User.ADsPath)
				DenyGroup.SetInfo
			'###Add user to "V2 Users" group###
				AllowGroup.Add(User.ADsPath)
				AllowGroup.SetInfo
			Next
      Call List_Allowed
      Call List_Denied
	End Sub
  
	Sub Deny_TSLogon			
			For Each UserName in AllowGroup.Members
				Set User = GetObject("WinNT://" & "Accounting" & "/" & UserName.Name & ",user")
      '###Remove from "V2 Users" group###
				AllowGroup.Remove(User.ADsPath)
				AllowGroup.SetInfo
			'###Add user to "Deny TS Logon" group###
				DenyGroup.Add(User.ADsPath)
				DenyGroup.SetInfo
			Next
      Call List_Allowed
      Call List_Denied
	End Sub
  
  Sub List_Allowed
      AllowedDiv.InnerHTML = ""
      strAllowList = ""
      arrayAllowed.Clear()
      For Each UserName in AllowGroup.Members
        arrayAllowed.Add UserName.Name         
      Next
        arrayAllowed.Sort
        For Each strUser in arrayAllowed
          strAllowList = strAllowList + "<option value=" + strUser + ">" + strUser + "</option>"
        Next
        AllowedDiv.InnerHTML = "<select name=""allowedusers"" multiple=""multiple"" size=""40"">" + strAllowList + "</select>"
  End Sub
  Sub List_Denied
      DeniedDiv.InnerHTML = ""
      strDenyList = ""
      arrayDenied.Clear()  
      For Each UserName in DenyGroup.Members
        arrayDenied.Add UserName.Name         
      Next
        arrayDenied.Sort
        For Each strUser in arrayDenied
         strDenyList = strDenyList + "<option value=" + strUser + ">" + strUser + "</option>"
        Next
        DeniedDiv.InnerHTML = "<select name=""deniedusers"" multiple=""multiple"" size=""40"">" + strDenyList + "</select>"
  End Sub
</script>

<body>
<b>Allow or deny access to the server through Terminal Services/Remote Desktop.</b><p>
<b>If you deny access to everyone, only the Administrator account will be able to log in via Remote Desktop.</b><p>
<br /><br />

<div id="DataArea">

<div id="AllowedColumn" align="center">             
<h2>Users allowed access to V2</h2>
<div id="AllowedDiv">
  <script>List_Allowed</script>
</div>
</div>

<div id="CenterDiv" align="center">
  Move all
  <br /><br />
  <input type="button" value=" << " name="run_button"  onClick="Allow_TSLogon">
  <br /><br />
  <input type="button" value=" >> " name="run_button"  onClick="Deny_TSLogon">
  <br /><br /><br /><br /><br /><br />
  Move Selected
  <br /><br />
  <input type="button" value=" < " name="run_button"  onClick="">
  <br /><br />
  <input type="button" value=" > " name="run_button"  onClick="">
  <br /><br />
</div>

<div id="DeniedColumn" align="center">             
<h2>Users denied access to V2</h2>
<div id="DeniedDiv">
  <script>List_Denied</script>
</div>
</div>


</div>
</body>
 
[0] I find it hard to show you how its done with a random mixed of different functionality and with styling standing at the middle. I can show you a clean functionality sheet with only the top part of your script. It will show you all the script functions you possibly need.

[1] I would say to have form element is important. Can you do without? yes, but, I don't think it is good to my book.

[2] This is the hta I can show as demo.
[tt]
<html>
<head>
<title>Terminal Server Access Control</title>
<HTA:APPLICATION
APPLICATIONNAME="Allow or deny Terminal Server access"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="maximize"
>

<script language="vbscript">
dim AllowGroup, DenyGroup

sub fill_up 'here you actually use WinNT: to populate all candidate user
'set up a global object
Set AllowGroup = GetObject("WinNT://" & "Accounting" & "/" & "V2 Users" & ",group")
Set DenyGroup = GetObject("WinNT://" & "Accounting" & "/" & "Deny TS Logon" & ",group")

dim a, osel, i, obj
'this array is established feeding all the user members of the group or whatever
'I use a proxy for the result of functionality
a=array("Accounting/john","Accounting/james","Accounting/patrick","Accounting/lisa")
set osel=document.formname.elements("sel_users")
for i=0 to ubound(a)
set obj=document.createElement("option")
with obj
.value=a(i)
.text=a(i)
end with
osel.options.add obj
set obj=nothing
next
set osel=nothing
erase a
end sub
sub add_list(starget)
dim osel, osel_target, i, j, obj
set osel=document.formname.elements("sel_users")
set osel_target=document.formname.elements(starget)
for i=1 to osel.length-1 '0 is reserved for title
if osel.options(i).selected then
bdup=false
for j=1 to osel_target.length-1 '0 is reserved for title
if osel_target.options(j).value=osel.options(i).value and _
osel_target.options(j).text=osel.options(i).text then
bdup=true
exit for
end if
next
if not bdup then
set obj=document.createElement("option")
with obj
.value=osel.options(i).value
.text=osel.options(i).text
end with
osel_target.options.add obj
osel.options(i).selected=false
end if
set obj=nothing
end if
next
set osel_target=nothing
set osel=nothing
end sub
sub deselect (selname)
dim osel, i
set osel=document.formname.elements(selname)
for i=osel.length-1 to 1 '0 is reserved
if osel.options(i).selected then
osel.options(i).parentNode.removeChild osel.options(i)
end if
next
end sub
sub exec(selname) 'all directory service script add here
dim oprovider, osel, i
select case selname
case "sel_allowed"
'use allowgroup object to do
set oprovider=AllowGroup
case "sel_denied"
set oprovider=DenyGroup
case else
set oprovider=nothing
end select
if not oprovider is nothing then
set osel=document.formname.elements(selname)
for i=0 to osel.length-1
'you have osel.options(i).value available here to use
'process all selected
next
end if
end sub

window.onload=getRef("fill_up")
</script>

<body>
<form name="formname">
<div>
<select name="sel_users" multiple="true" size="10" style="width:20%;">
<option value="">-- all users --</option>
</select>
<input type="button" onclick="add_list('sel_allowed')" value=">>allowed>>" />
<input type="button" onclick="add_list('sel_denied')" value=">>denied>>" />
</div>
<div>
<select name="sel_allowed" multiple="true" size="10" style="width:20%;">
<option value="">-- allowed users --</option>
</select>
<input type="button" onclick="exec('sel_allowed')" value="exec_allowed" />
<input type="button" onclick="deselect('sel_allowed')" value="deselect" />
</div>
<div>
<select name="sel_denied" multiple="true" size="10" style="width:20%;">
<option value="">-- denied users --</option>
</select>
<input type="button" onclick="exec('sel_denied')" value="exec_denied" />
<input type="button" onclick="deselect('sel_denied')" value="deselect" />
</div>
</form>

</body>
</html>
[/tt]
[3] Watch typo or else. It is tested only in the big picture. Detail, you've to pick up.
 
amendment
I have this statement wrongly edited last minute.
>[self]>for i=osel.length-1 to 1 '0 is reserved
It should sure be read like this.
[tt]for i=osel.length-1 to 1 [red]step -1[/red] '0 is reserved[/tt]
 
Thanks for the reply tsuji. I just now finished figuring out a way to do what I needed. Below is what I came up with. It's not as nice as yours, but I'm just happy that I managed to accomplish what I wanted mostly on my own.

Code:
...
<script language="VBScript">
Option Explicit
Dim AllowGroup,arrayAllowed,arrayDenied,arrayOptions,DenyGroup,objOption
Dim strAllowList,strDenyList,strSelectedUsers,strUser,strUserValue,User,UserName

Set AllowGroup = GetObject("WinNT://" & "Accounting" & "/" & "V2 Users" & ",group")
Set DenyGroup = GetObject("WinNT://" & "Accounting" & "/" & "Deny TS Logon" & ",group") 
Set arrayAllowed = CreateObject( "System.Collections.ArrayList" )
Set arrayDenied = CreateObject( "System.Collections.ArrayList" )
Set arrayOptions = CreateObject( "System.Collections.ArrayList" )

	Sub subAllow_TSLogon			
			For Each UserName in DenyGroup.Members
				Set User = GetObject("WinNT://" & "Accounting" & "/" & UserName.Name & ",user")
			'###Remove from "Deny Ts Logon" group###
        DenyGroup.Remove(User.ADsPath)
				DenyGroup.SetInfo
			'###Add user to "V2 Users" group###
				AllowGroup.Add(User.ADsPath)
				AllowGroup.SetInfo
			Next
      Call subList_Allowed
      Call subList_Denied
	End Sub
  
	Sub subDeny_TSLogon			
			For Each UserName in AllowGroup.Members
				Set User = GetObject("WinNT://" & "Accounting" & "/" & UserName.Name & ",user")
      '###Remove from "V2 Users" group###
				AllowGroup.Remove(User.ADsPath)
				AllowGroup.SetInfo
			'###Add user to "Deny TS Logon" group###
				DenyGroup.Add(User.ADsPath)
				DenyGroup.SetInfo
			Next
      Call subList_Allowed
      Call subList_Denied
	End Sub
  
  Sub subList_Allowed
      AllowedDiv.InnerHTML = ""
      strAllowList = ""
      arrayAllowed.Clear()
      For Each UserName in AllowGroup.Members
        arrayAllowed.Add UserName.Name         
      Next
        arrayAllowed.Sort
        For Each strUser in arrayAllowed
          strAllowList = strAllowList + "<option value=" + strUser + ">" + strUser + "</option>"
        Next
        AllowedDiv.InnerHTML = "<select name=""allowedusers"" multiple=""multiple"" size=""40"">" + strAllowList + "</select>"
  End Sub
  
  Sub subList_Denied
      DeniedDiv.InnerHTML = ""
      strDenyList = ""
      arrayDenied.Clear()  
      For Each UserName in DenyGroup.Members
        arrayDenied.Add UserName.Name         
      Next
        arrayDenied.Sort
        For Each strUser in arrayDenied
         strDenyList = strDenyList + "<option value=" + strUser + ">" + strUser + "</option>"
        Next
        DeniedDiv.InnerHTML = "<select name=""deniedusers"" multiple=""multiple"" size=""40"">" + strDenyList + "</select>"
  End Sub
  
  Sub subMovetoDenied
      arrayOptions.Clear()
      strDenylist = ""
      For Each objOption In allowedusers.options
        If objOption.Selected Then
          arrayOptions.add objOption.Value
        Else
        End if
      Next
      For Each strUser in arrayOptions
         Set User = GetObject("WinNT://" & "Accounting" & "/" & strUser & ",user")
         '###Remove from "V2 Users" group###
         AllowGroup.Remove(User.ADsPath)
				 AllowGroup.SetInfo
			   '###Add user to "Deny TS Logon" group###
				 DenyGroup.Add(User.ADsPath)
				 DenyGroup.SetInfo
      Next
      'DeniedDiv.InnerHTML = "<select name=""deniedusers"" multiple=""multiple"" size=""40"">" + strDenyList + "</select>"
      Call subList_Allowed
      Call subList_Denied
  End Sub
  
  Sub subMoveToAllowed
      arrayOptions.Clear()
      strAllowlist = ""
      For Each objOption In deniedusers.options
        If objOption.Selected Then
          arrayOptions.add objOption.Value
        Else
        End if
      Next
      For Each strUser in arrayOptions
         Set User = GetObject("WinNT://" & "Accounting" & "/" & strUser & ",user")
         '###Remove from "Deny TS Logon" group###
         DenyGroup.Remove(User.ADsPath)
				 DenyGroup.SetInfo
			   '###Add user to "V2 Users" group###
				 AllowGroup.Add(User.ADsPath)
				 AllowGroup.SetInfo
      Next
      Call subList_Allowed
      Call subList_Denied
  End Sub 
</script>

<body>
<b>Allow or deny access to the server through Terminal Services/Remote Desktop.</b><p>
<b>If you deny access to everyone, only the Administrator account will be able to log in via Remote Desktop.</b><p>
<br /><br />

<div id="DataArea">

<div id="AllowedColumn" align="center">             
<h2>Users allowed access to V2</h2>
<div id="AllowedDiv">
  <script>subList_Allowed</script>
</div>
</div>

<div id="CenterDiv" align="center">
  Move all
  <br /><br />
  <input type="button" value=" << " name="run_button"  onClick="subAllow_TSLogon">
  <br /><br />
  <input type="button" value=" >> " name="run_button"  onClick="subDeny_TSLogon">
  <br /><br /><br /><br /><br /><br />
  Move Selected
  <br /><br />
  <input type="button" value=" < " name="run_button"  onClick="subMoveToAllowed">
  <br /><br />
  <input type="button" value=" > " name="run_button"  onClick="subMoveToDenied">
  <br /><br />
</div>

<div id="DeniedColumn" align="center">             
<h2>Users denied access to V2</h2>
<div id="DeniedDiv">
  <script>subList_Denied</script>
</div>
</div>


</div>
</body>
 
amendment-2
In the sub exec the indexing is from 1 to osel.length-1 for the same reason.
>[self, inside sub exec]>for i=0 to osel.length-1
It should be read like this.
[tt]for i=[red]1[/red] to osel.length-1[/tt]

ps: Go for your own script. I've not scrutinize it. No problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top