HTA per Creazione Utenti e Gruppi locali Microsoft

Posted on 4 giugno 2012 di

0


Di seguito il codice per creare utenti e gruppi locali da una semplice interfaccia mediante HTA.

 

 

 

 

 

 

 

 

 

 

 

Di seguito il codice per creare l’interfaccia. Popolare Group (0) etc. con i valori che si preferiscono.

<html>
<head>
<title>Customizza Postazione </title>
<HTA:APPLICATION
ID = “AccountCreationApp”
APPLICATIONNAME=”Account Creation”
BORDER = “thin”
CAPTION = “yes”
RESIZE = “no”
ICON = “sprocket.ico”
SHOWINTASKBAR = “yes”
SINGLEINSTANCE = “yes”
SYSMENU = “yes”
WINDOWSTATE = “normal”
SCROLL = “no”
SCROLLFLAT = “no”
VERSION = “1.0”
INNERBORDER = “no”
SELECTION = “no”
MAXIMIZEBUTTON = “no”
MINIMIZEBUTTON = “yes”
NAVIGABLE = “yes”
CONTEXTMENU = “yes”
BORDERSTYLE = “normal”>
</hta>
<style>
BODY
{
background-color: #FF9000;
font-family: Helvetica;
font-size: 8pt;
margin-top: 10px;
margin-left: 20px;
margin-right: 10px;
margin-bottom: 10px;
scrollbar-track-color: #6609F43;
scrollbar-3dlight-color: #609F43;
scrollbar-arrow-color: #609F43;
scrollbar-base-color: #609F43;
scrollbar-darkshadow-color: #609F43;
scrollbar-face-color: #609F43;
scrollbar-highlight-color: #609F43;
scrollbar-shadow-color: #609F43
}
TD
{
font-family: Trebuchet MS;
font-size: 8pt;
}
LEGEND
{
font-family: Trebuchet MS;
font-size: 10pt;
}
SELECT
{
font-family: Trebuchet MS;
font-size: 8pt;
width:195px
}
INPUT
{
font-family: Trebuchet MS;
font-size: 8pt;
}
</style>

<script language=”VBScript”>
sub window_onload
Dim x,y
x = (window.screen.width – 750) / 2
y = (window.screen.height – 700) / 2
‘If x < 0 Then x = 0
‘If y < 0 Then y = 0
window.moveTo x,y
Window.SetTimeout “window.resizeTo 420,280”, 100

end sub

sub CreateAccount
Dim objFSO, Group(2), GroupAss(2), risp
Set wshShell = CreateObject( “WScript.Shell” )
‘strUserName = “prova2”
strUserName = txtUser.Value
‘strPassword = “Password10”
strPassword = txtPassword.Value
strPassword2 = txtPassword2.Value
Group(0) = “Sicurezza”
Group(1) = “Amministrazione”
Group(2) = “Operatori”

GroupAss(0) = “Administrators”
‘GroupAss(1) = Group(0)
GroupAss(1) = cbxSite.Value

if strUsername = “” or strPassword = “” or strPassword2 = “” then
x = MsgBox (“E’ necessario compilare tutti i campi”,16)
‘Location.Reload(True)
exit sub
end if

if GroupAss(1) = “cbxGroup” then
x = MsgBox (“E’ necessario selezionare un gruppo”,16)
‘Location.Reload(True)
exit sub
end if

if strPassword <> strPassword2 then
x = MsgBox (“La password non coincide”,16)
Location.Reload(True)
exit sub
end if

 

strComputer = wshShell.ExpandEnvironmentStrings( “%COMPUTERNAME%” )
‘MsgBox “Computer Name: ” & strComputer
set objSystem = GetObject(“WinNT://” & strComputer)
‘Creazione gruppi locali
Dim i
i = 0
for i = 0 to 2
On error resume next
set objGroup = GetObject (“WinNT://” & strComputer & “/” & Group(i) & “,group”)
‘MsgBox “Error: ” & Err.Number
select case Err.Number
Case 0
MsgBox (“Il gruppo” & (chr(32)) & Group(i) & (chr(32)) & “non è stato creato perchè esistente”)
Case -2147022676
Set objGroupNew = objSystem.Create(“group”, Group(i))
objGroupNew.SetInfo
MsgBox (“E’ stato creato il gruppo:” & (chr(32)) & Group(i))
end Select
Err.Clear
next

‘Creo Utente
set objUser = GetObject (“WinNT://” & strComputer & “/” & strUserName & “,user”)
‘MsgBox “Error: ” & Err.Number
select case Err.Number
Case 0
MsgBox (“L’utente” & (chr(32)) & strUserName & (chr(32)) &”non è stato creato, perchè già esistente”)
Case -2147022675
set objUser = objSystem.Create(“user”, strUserName)
objUser.SetPassword strPassword
objUser.SetInfo
MsgBox (“E’ stato creato l’utete:”& (chr(32)) & strUserName)
end Select
Err.Clear
‘ Assegno utente al gruppo Administrators e ai Gruppi applicazione
Dim t
t = 0
for t = 0 to 1
set objGroupAss = GetObject(“WinNT://” & strComputer & “/” & GroupAss(t) & “,group”)
‘set objUser = GetObject (“WinNT://” & strComputer & “/” & strUserName & “,user”)
If (objGroupAss.IsMember(objUser.AdsPath) = True) Then
MsgBox(strUserName & (chr(32)) & “è già membro del gruppo “& GroupAss(t))
else
MsgBox(strUserName & (chr(32)) & “è stato aggiunto al gruppo “& GroupAss(t))
objGroupAss.Add(objUser.ADsPath)
End If
next

‘ Verifico riavvio server
Location.Reload(True)
end sub

Sub Reload
Location.Reload(True)
End Sub

‘ ## Closes page on pressing [Exit] ##
Sub CloseForm
Window.Close
End Sub
</script>
<body>
<table width=”710″ border=”0″ cellspacing=”0″ CellSpacing=”0″>
<tr><td width=”350″ Valign=”top”>
<!– LHS Of Main Table –>
<table border=”0″ cellspacing=”0″ CellSpacing=”0″>
<tr><td width=”350″>
<!– Username –>
<table border=”0″ cellspacing=”0″ CellSpacing=”0″ width=”350″>
<tr><td valign=”top” colspan=”3″><fieldset><legend><b>Creazione Utente</b></legend>
<table border=”0″ cellpadding=”3″ width=”350″>
<tr><td>Username: </td><td><input type=”text” name=”txtUser” style=”width:195px”></td><td>&nbsp;</td></tr>
<tr><td>Password: </td><td><input type=”password” name=”txtPassword” style=”width:195px”></td><td
width=”50″>&nbsp;</td></tr>
<tr><td>Ripeti Password: </td><td><input type=”password” name=”txtPassword2″ style=”width:195px”></td><td
width=”50″>&nbsp;</td></tr>

<tr><td>Seleziona Gruppo: </td>
<td align=”right”>
<select size=”1″ name=”cbxSite”>
<option value=”Amministrazione”>Amministrazione</option>
<option value=”Operatori”>Operatori</option>
<option value=”Sicurezza”>Sicurezza</option>
<option selected value=”cbxGroup”>– Selezione Gruppo –</option>
</select></td>
</table><p></fieldset></table>
<td>&nbsp;</td>
</tr>
<table border=”0″ cellspacing=”0″ cellpadding=”0″ width=”350″>
<tr>
<td align=”right” valign=”bottom”>

<input type=”button” value=”Clear Form” onclick=”Reload” title=” Click to Clear Form “>
<input type=”button” value=” Submit ” onClick=”CreateAccount” title=” Click to Create User Account “>
<input type=”button” value=” Exit ” onclick=”CloseForm” title=” Click to Exit Form “>
</td></tr>
</table>
</body>
</html>

 

Annunci
Posted in: Microsoft, scripting