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

Using HTA to create local accounts on servers 1

Status
Not open for further replies.

teckiejon

Technical User
Feb 25, 2004
47
GB
I am currently working in an environment where I am managing 30 servers which are all in workgroups. As this new project kicks off I am being asked with increasing frequency to create accounts on these servers. I decided that the best way to do this would be to automate the process using VB script. I ran a script to create a basic account which works fine but when I have tried to implement the same script using an hta page the results never get passed through. Could somebody please take a quick glance and point me in the right direction:

Here is the code:

<HEAD>
<TITLE>Create Local User Account</TITLE>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Drop Down"
BORDER="Dialog"
CAPTION="Yes"
SCROLL="NO"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="Yes"
WINDOWSTATE="maximize">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">

Sub Window_OnLoad
Window.Server.Focus
End Sub

Sub btn01_OnClick
Dim strSvr

oElements = Window.Server.SelectedIndex
strProduct = Window.Server.Options(oElements).Text


Select Case strSvr
Case "server1"
cmpname = "192.168.0.1"
Case "server2"
cmpname = "192.168.0.2"
Case "server3"
cmpname = "192.168.0.3"
Case "server4"
cmpname = "192.168.0.4"
End Select


Set colaccounts = GetObject("WinNT://" & cmpname)
Set objUser = colaccounts.Create("user",Name)
objUser.SetInfo
objUser.SetPassword "" & strpass
objUser.SetInfo

End Sub

Sub btn02_OnClick
Window.Close
End Sub
</SCRIPT>


<H2>Create A New Account</H2>
<P>Please select the Server:
<SELECT NAME="Server">
<OPTION>server1</OPTION>
<OPTION>server2</OPTION>
<OPTION>server3</OPTION>
<OPTION>server4</OPTION>
</SELECT><P>

Name <br>
<INPUT TYPE="text" NAME="name" SIZE="40" MAXLENGTH="60"><BR>

Password <br>
<INPUT TYPE="text" NAME="strpass" SIZE="40" MAXLENGTH="60"><BR>

Username<br>
<INPUT TYPE="text" NAME="struname" SIZE="40" MAXLENGTH="60"><BR>


<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "SUBMIT">
<Input Type = "Button" Name = "btn02" VALUE = "CLOSE">
<BR>
<BR>

</BODY>

Thanks for your time
 
teckiejon,

I'm not convinced the script is serious enough to do a minimal job. Nevertheless, the indications I put in this revision might inspire you to put in some devices making the functionality perform properly. I do not attempt to make much change to the naming conventions which are not very good yet.
[tt]
<HTML>
<HEAD>
<TITLE>Create Local User Account</TITLE>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Drop Down"
BORDER="Dialog"
CAPTION="Yes"
SCROLL="NO"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="Yes"
WINDOWSTATE="maximize">
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">

Sub Window_OnLoad
'Window.Server.Focus
document.getElementsByName("Server")(0).focus
End Sub

Sub btn01_OnClick
Dim strSvr

'oElements = Window.Server.SelectedIndex
'strProduct = Window.Server.Options(oElements).Text

idxsel = document.getElementsByName("Server")(0).SelectedIndex
strSvr = document.getElementsByName("Server")(0).Options(idxsel).Text
msgbox strSvr,,"HTA"

Select Case strSvr
Case "server1"
cmpname = "192.168.0.1"
Case "server2"
cmpname = "192.168.0.2"
Case "server3"
cmpname = "192.168.0.3"
Case "server4"
cmpname = "192.168.0.4"
End Select
msgbox cmpname,,"HTA"

'Set colaccounts = GetObject("WinNT://" & cmpname)
sname=document.getElementsByName("NAME")(0).value
'Set objUser = colaccounts.Create("user",sname)
'objUser.SetInfo
spass=document.getElementsByName("strpass")(0).value
'objUser.SetPassword "" & spass
'objUser.SetInfo
msgbox "sname : " & sname & vbcrlf & "spass : " & spass,,"HTA"

End Sub

Sub btn02_OnClick
Window.Close
End Sub
</SCRIPT>


<H2>Create A New Account</H2>
<P>Please select the Server:
<SELECT NAME="Server">
<OPTION>server1</OPTION>
<OPTION>server2</OPTION>
<OPTION>server3</OPTION>
<OPTION>server4</OPTION>
</SELECT><P>

Name <br>
<INPUT TYPE="text" NAME="name" SIZE="40" MAXLENGTH="60"><BR>

Password <br>
<!--
<INPUT TYPE="text" NAME="strpass" SIZE="40" MAXLENGTH="60"><BR>
-->
<INPUT TYPE="password" NAME="strpass" SIZE="40" MAXLENGTH="60"><BR>

Username<br>
<INPUT TYPE="text" NAME="struname" SIZE="40" MAXLENGTH="60"><BR>


<BR>
<BR>
<Input Type = "Button" Name = "btn01" VALUE = "SUBMIT">
<Input Type = "Button" Name = "btn02" VALUE = "CLOSE">
<BR>
<BR>

</BODY>
</HTML>
[/tt]
Msgboxes are for you to see what you get. ADSI operations are commented out as the script is far from ready yet.

regards - tsuji
 
Thankyou Tsuji

I shall take on board what you have said and let you know the final result once it has all been tidied up

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top