M
MattW
HI all. I'm trying to create a tabbed HTA that allows me to pull a
list of user groups on one tab, compare groups on another tab, and
assign groups on the 3rd tab. The first and second tabs will display
the list of groups in an innerHTML, but the button to run the function
isn't working. Here's the code I'm using:
<html>
<head>
<title>AD User Group Migration Tool</title>
<link href="testweb.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
hideLayer('lyr3')
var origWidth, origHeight;
if (document.layers) {
origWidth = window.innerWidth; origHeight = window.innerHeight;
window.onresize = function() { if (window.innerWidth != origWidth ||
window.innerHeight != origHeight) history.go(0); }
}
var cur_lyr;
function swapLayers(id) {
if (cur_lyr) hideLayer(cur_lyr);
showLayer(id);
cur_lyr = id;
}
function showLayer(id) {
var lyr = getElemRefs(id);
if (lyr && lyr.css) lyr.css.display = "block";
}
function hideLayer(id) {
var lyr = getElemRefs(id);
if (lyr && lyr.css) lyr.css.display = "none";
}
function getElemRefs(id) {
var el = (document.getElementById)? document.getElementById(id):
(document.all)? document.all[id]: (document.layers)?
document.layers[id]: null;
if (el) el.css = (el.style)? el.style: el;
return el;
}
var arrUsers = new Array(1);
WshNetwork = new ActiveXObject("Wscript.Network");
strUserDomain = WshNetwork.UserDomain
function ExitProgram(){
window.close();
}
function TabStrip_Change(){
switch(TabStrip.Value){
case 0:
Page1.style.visibility = "hidden";
Page0.style.visibility = "visible";
Page2.style.visibility = "hidden";
case 1:
Page0.style.visibility = "hidden";
Page1.style.visibility = "visible";
Page2.style.visibility = "hidden";
case 2:
Page0.style.visibility = "hidden";
Page1.style.visibility = "hidden";
Page2.style.visibility = "visible";
}
}
function btnGet_Click(){
var sUser1 = User1.value ;
var sUser2 = User2.value;
for (oGroup in objUser.Groups)
{
var sGroups = sGroups + oGroup.Name + '\r\n' + "<br>" ;
}
Next ;
document.getElementById('DataArea').innerHTML = sGroups;
}
// Constants for the NameTranslate object.
function btnComp_Click(){
WshNetwork = new ActiveXObject("Wscript.Network");
arrUsers(0) = User1.value;
arrUsers(1) = User2.value;
for (i = 0; i<=1
if(i = 0){
UserGroup1.InnerHTML = GetAllGroups(i);
}else if(i = 1){
UserGroup2.InnerHTML = GetAllGroups(i);
}
Next;
}
function btnRun_Click(){
//text box values
sUser1 = User1.value;
sUser2 = User2.value;
objUser = GetObject("WinNT://" + strUserDomain + "/" + sUser1)
objTemplate = GetObject("WinNT://" + strUserDomain + "/" + sUser2)
//Pull the Groups for the Template user.
for (oGroup in objTemplate.Groups);
//Check to see if(the user is already a member;
if((ogroup.ismember(objUser.adspath)=False)){;
//Add the new user to this group;
ogroup.Add(objUser.AdsPath);
sGroups = sGroups + oGroup.Name + '\r\n' + "<br>";
}
Next;
DataArea.InnerHTML = sGroups;
}
//Put application in wait &&){ clear
/**
* Delay for a number of milliseconds
*/
function sleepwait(delay){
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
Initialize(4)
}
//Clear variables
function Initialize(){
user1.value = "";
user2.value = "";
Message.InnerHTML = "";
document.getElementById('DataArea').innerHTML = "";
document.getElementById('UserGroup1').innerHTML = "";
document.getElementById('UserGroup2').innerHTML = "";
}
function GetAllGroups(i){
// On Error Resume Next
WshNetwork = new ActiveXObject("Wscript.Network") ;
strDN = WshNetwork.UserDomain;
sUser = arrusers(i);
objUser = GetObject("WinNT://" + strDN + "/" + sUser);
for (oGroup in objUser.Groups);
sGroups = sGroups + oGroup.Name + '\r\n' + "<br>";
Next;
GetAllGroups = sGroups;
}
function Testing(){
document.getElementById('DataArea').innerHTML = "";
}
</SCRIPT>
</head>
<body onload="swapLayers('lyr1')">
<div id="section-4">
<ul id="menu">
<li><a href="javascript:void(0)" class="nav-1"
onclick="swapLayers('lyr1'); return false">Get Groups</a></li>
<li><a href="javascript:void(0)" class="nav-2"
onclick="swapLayers('lyr2'); return false">Compare Groups</a></li>
<li><a href="javascript:void(0)" class="nav-3"
onclick="swapLayers('lyr3'); return false">Assign Groups</a></li>
</ul>
<table id="contents"><tr><td align="left" valign="top">
<div id="lyr1">
<form id="horizontalForm" action="">
<input id="sUser1" name="sUser1" type="text"/>
<input type="button" id="btnGet_Click" value="Get Groups" class="btn"
onmouseover="this.className='btn btnhov'"
onmouseout="this.className='btn'" onclick="btnGet_Click()" />
<p id="DataArea">This is the Data Area.</p>
</div>
<div id="lyr2">
<div class="alignCenter"><label class="alignTopLeft" for="User1">
<strong>First User ID</strong></label></div>
<div class="alignCenter"><input name="User1" id="User1" size="30"
maxlength="30" /></div>
<input type="button" value="Get Groups" name="btnGet"
onClick="btnGet_Click" STyle='background-color: ButtonFace;'
STyle='color:ButtonText;'>
<br>
<div class="alignCenter"><label class="alignTopLeft" for="User2">
<strong>Second User ID</strong></label></div>
<div class="alignCenter"><input name="User2" id="User1" size="30"
maxlength="30" /></div>
</div>
<div id="lyr3">
<div class="alignCenter"><label class="alignTopLeft" for="User1">
<strong>New User ID</strong></label></div>
<div class="alignCenter"><input name="User1" id="User1" size="30"
maxlength="30" /></div>
<br>
<div class="alignCenter"><label class="alignTopLeft" for="User2">
<strong>Template User ID</strong></label></div>
<div class="alignCenter"><input name="User2" id="User1" size="30"
maxlength="30" /></div>
</div>
</td></tr></table>
</div>
</body>
</html>
The javascript portion is an attempt at a translation from vbscript,
and doesn't give me any errors when I compile, but I get an "Object
doesn't support this property or method" error when I click the Get
Groups Button. If I change the onClick to the Testing() function, it
works, so the problem has to be something in my btnGet_Click
function. Could someone look at this and help me determine where I'm
going wrong? Thanks!
list of user groups on one tab, compare groups on another tab, and
assign groups on the 3rd tab. The first and second tabs will display
the list of groups in an innerHTML, but the button to run the function
isn't working. Here's the code I'm using:
<html>
<head>
<title>AD User Group Migration Tool</title>
<link href="testweb.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
hideLayer('lyr3')
var origWidth, origHeight;
if (document.layers) {
origWidth = window.innerWidth; origHeight = window.innerHeight;
window.onresize = function() { if (window.innerWidth != origWidth ||
window.innerHeight != origHeight) history.go(0); }
}
var cur_lyr;
function swapLayers(id) {
if (cur_lyr) hideLayer(cur_lyr);
showLayer(id);
cur_lyr = id;
}
function showLayer(id) {
var lyr = getElemRefs(id);
if (lyr && lyr.css) lyr.css.display = "block";
}
function hideLayer(id) {
var lyr = getElemRefs(id);
if (lyr && lyr.css) lyr.css.display = "none";
}
function getElemRefs(id) {
var el = (document.getElementById)? document.getElementById(id):
(document.all)? document.all[id]: (document.layers)?
document.layers[id]: null;
if (el) el.css = (el.style)? el.style: el;
return el;
}
var arrUsers = new Array(1);
WshNetwork = new ActiveXObject("Wscript.Network");
strUserDomain = WshNetwork.UserDomain
function ExitProgram(){
window.close();
}
function TabStrip_Change(){
switch(TabStrip.Value){
case 0:
Page1.style.visibility = "hidden";
Page0.style.visibility = "visible";
Page2.style.visibility = "hidden";
case 1:
Page0.style.visibility = "hidden";
Page1.style.visibility = "visible";
Page2.style.visibility = "hidden";
case 2:
Page0.style.visibility = "hidden";
Page1.style.visibility = "hidden";
Page2.style.visibility = "visible";
}
}
function btnGet_Click(){
var sUser1 = User1.value ;
var sUser2 = User2.value;
for (oGroup in objUser.Groups)
{
var sGroups = sGroups + oGroup.Name + '\r\n' + "<br>" ;
}
Next ;
document.getElementById('DataArea').innerHTML = sGroups;
}
// Constants for the NameTranslate object.
function btnComp_Click(){
WshNetwork = new ActiveXObject("Wscript.Network");
arrUsers(0) = User1.value;
arrUsers(1) = User2.value;
for (i = 0; i<=1
if(i = 0){
UserGroup1.InnerHTML = GetAllGroups(i);
}else if(i = 1){
UserGroup2.InnerHTML = GetAllGroups(i);
}
Next;
}
function btnRun_Click(){
//text box values
sUser1 = User1.value;
sUser2 = User2.value;
objUser = GetObject("WinNT://" + strUserDomain + "/" + sUser1)
objTemplate = GetObject("WinNT://" + strUserDomain + "/" + sUser2)
//Pull the Groups for the Template user.
for (oGroup in objTemplate.Groups);
//Check to see if(the user is already a member;
if((ogroup.ismember(objUser.adspath)=False)){;
//Add the new user to this group;
ogroup.Add(objUser.AdsPath);
sGroups = sGroups + oGroup.Name + '\r\n' + "<br>";
}
Next;
DataArea.InnerHTML = sGroups;
}
//Put application in wait &&){ clear
/**
* Delay for a number of milliseconds
*/
function sleepwait(delay){
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
Initialize(4)
}
//Clear variables
function Initialize(){
user1.value = "";
user2.value = "";
Message.InnerHTML = "";
document.getElementById('DataArea').innerHTML = "";
document.getElementById('UserGroup1').innerHTML = "";
document.getElementById('UserGroup2').innerHTML = "";
}
function GetAllGroups(i){
// On Error Resume Next
WshNetwork = new ActiveXObject("Wscript.Network") ;
strDN = WshNetwork.UserDomain;
sUser = arrusers(i);
objUser = GetObject("WinNT://" + strDN + "/" + sUser);
for (oGroup in objUser.Groups);
sGroups = sGroups + oGroup.Name + '\r\n' + "<br>";
Next;
GetAllGroups = sGroups;
}
function Testing(){
document.getElementById('DataArea').innerHTML = "";
}
</SCRIPT>
</head>
<body onload="swapLayers('lyr1')">
<div id="section-4">
<ul id="menu">
<li><a href="javascript:void(0)" class="nav-1"
onclick="swapLayers('lyr1'); return false">Get Groups</a></li>
<li><a href="javascript:void(0)" class="nav-2"
onclick="swapLayers('lyr2'); return false">Compare Groups</a></li>
<li><a href="javascript:void(0)" class="nav-3"
onclick="swapLayers('lyr3'); return false">Assign Groups</a></li>
</ul>
<table id="contents"><tr><td align="left" valign="top">
<div id="lyr1">
<form id="horizontalForm" action="">
<input id="sUser1" name="sUser1" type="text"/>
<input type="button" id="btnGet_Click" value="Get Groups" class="btn"
onmouseover="this.className='btn btnhov'"
onmouseout="this.className='btn'" onclick="btnGet_Click()" />
<p id="DataArea">This is the Data Area.</p>
</div>
<div id="lyr2">
<div class="alignCenter"><label class="alignTopLeft" for="User1">
<strong>First User ID</strong></label></div>
<div class="alignCenter"><input name="User1" id="User1" size="30"
maxlength="30" /></div>
<input type="button" value="Get Groups" name="btnGet"
onClick="btnGet_Click" STyle='background-color: ButtonFace;'
STyle='color:ButtonText;'>
<br>
<div class="alignCenter"><label class="alignTopLeft" for="User2">
<strong>Second User ID</strong></label></div>
<div class="alignCenter"><input name="User2" id="User1" size="30"
maxlength="30" /></div>
</div>
<div id="lyr3">
<div class="alignCenter"><label class="alignTopLeft" for="User1">
<strong>New User ID</strong></label></div>
<div class="alignCenter"><input name="User1" id="User1" size="30"
maxlength="30" /></div>
<br>
<div class="alignCenter"><label class="alignTopLeft" for="User2">
<strong>Template User ID</strong></label></div>
<div class="alignCenter"><input name="User2" id="User1" size="30"
maxlength="30" /></div>
</div>
</td></tr></table>
</div>
</body>
</html>
The javascript portion is an attempt at a translation from vbscript,
and doesn't give me any errors when I compile, but I get an "Object
doesn't support this property or method" error when I click the Get
Groups Button. If I change the onClick to the Testing() function, it
works, so the problem has to be something in my btnGet_Click
function. Could someone look at this and help me determine where I'm
going wrong? Thanks!