Hi ppl
i am in need for some help on a usermanager script i am writing.
My problems is this, when using this code snippet i found on Technet i want
to substitue the C:\finance and FianaceShare with a variable.
these are declared before this code and can pop a message box fine so i know
they are working fine. When i drop the quotes and just put in a variable i
get an error expected ]

any help would be much appreciated

Daz

Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")
errReturn = objNewShare.Create _
("C:\Finance", "FinanceShare", FILE_SHARE, _
MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
Wscript.Echo errReturn

Re: passing variables by Liz

Liz
Wed Aug 16 10:21:58 CDT 2006

How about posting your altered code segment, as well as the value in
the variables that the error occurs with.

Re: passing variables by Darren

Darren
Wed Aug 16 13:44:02 CDT 2006

Hi Liz
thx for your response here goes. This is a HTA for use at a
school i work in. Because we have so many staff and pupils go through the
school i wanted to design our own user manager that creates the username maps
the drives and all the other stuff that comes with setting up a user.
The main problem with this is when i try to concatenate the string variable
and suffix the share with a $ to hide it on the network also concatenating
the folder string variable causes me problems as with my other post.

The Sub Routine is called createshare all the other part of the code works
fine

many thanks

Darren


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

<html>
<head>
<HTA:APPLICATION
APPLICATIONNAME="Account Creator"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="Normal"
>
<script language="VBScript">
'Option Explicit

Public strfolders
Public strusers
Public strGroup
Public strpassword
Public strlenpassword
Public strserver


Sub ExitHTA
self.close()
End Sub

Sub Window_onLoad
window.resizeTo 980,370
End Sub

'The browsefor Sub Routine creates a value for the Foldertxt textbox for
users home folder
'********************************************************************************************************
Sub browsefor
Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Const OPTIONS = 0

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a folder:", OPTIONS, strPath)

If objFolder Is Nothing Then
Exit Sub
End If

Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
foldertxt.value = objPath


End Sub


Sub Showbatch
Msgbox selectbatch1.value
End Sub

Sub CreateUserAccount
strserver = (Serverlist.value)
strusers = (usernametxt.value)
strGroup = (grouptxt.value)
strpassword = (passwordtxt.value)
strlenpassword = Len(strpassword)
strfolders = (foldertxt.value)


'Check lengh of password string
'************************************************************************************************
If strlenpassword < 6 Then
Msgbox "You must provide a password of at least 6 characters or more"
Exit Sub

End If

'This creates the folder based on the location in the make home folder
'*************************************************************************************************
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder3 = objFSO.CreateFolder (Foldertxt.value & "\" & strusers)


'Write user info to Active Directory
'*************************************************************************************************
Set objOU = GetObject("LDAP://ou=" & (StrGroup) & "," &
"ou=Pupils,DC=wpsdom,DC=Local")
Set objUser = objOU.Create("user", "cn=" & (usernametxt.value))
objUser.Put "sAMAccountName", usernametxt.value
objUser.Put "givenName", forenametxt.value
objUser.Put "sn", surnametxt.value
objUser.Put "displayName", surnametxt.value & " " & forenametxt.value
objUser.LoginScript = logonscripttxt.value

objUser.HomeDirectory = homedrvtxt.value
objUser.Put "homeDrive", drivelistmenu.value

objUser.Put "description", descriptiontxt.value
objUser.Put "mail", (usernametxt.value & "@wpsdom.local")
objUser.Put "userPrincipalName", (usernametxt.value & "@wpsdom.local")
objUser.Setinfo
objUser.Put "SetPassword", (passwordtxt.value)

'This enables the account provided a password has been entered
'*************************************************************************************************
Const ADS_UF_ACCOUNTDISABLE = 2

Set objUser1 = GetObject("LDAP://cn=" & strusers & _
"," & "ou="&(StrGroup) & "," & "ou=Pupils" & "," & "dc=wpsdom" & "," &
"dc=local")
intUAC = objUser1.Get("userAccountControl")

If intUAC AND ADS_UF_ACCOUNTDISABLE Then
objUser1.Put "userAccountControl", intUAC XOR ADS_UF_ACCOUNTDISABLE
objUser1.SetInfo
End If
'************************************************************************************************
'Join user to a group
'************************************************************************************************
Set oDomain = GetObject("WinNT://wpsdom.local")
Set oGroup = oDomain.GetObject("Group", strGroup)
oGroup.Add ("WinNT://wpsdom.local/" & strusers)


'************************************************************************************************
'This refreshes the HTA Form and sets all fields to blank



Location.Reload(True)

Msgbox "Account " & strusers & " Created Successfully"
CALL createshare
End Sub

'Share Pupil Folder
'************************************************************************************************
Sub createshare

strserver = (Serverlist.value)
strusers = (usernametxt.value)
strGroup = (grouptxt.value)
strpassword = (passwordtxt.value)
strlenpassword = Len(strpassword)
strfolders = (foldertxt.value)
strusershare = (foldertxt.value) & "$"

Const FILE_SHARE = 2147483648
Const MAXIMUM_CONNECTIONS = 0
strcomputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set objNewShare = objWMIService.Get("Win32_Share")

errReturn = objNewShare.Create _
strfolders & "\" & strusers & "," strusershare & "," FILE_SHARE, _
MAXIMUM_CONNECTIONS, "Public share for the Finance group.")


Msgbox errReturn



End Sub

'******************** Checks Active Directroy for
username'**************************************
'************************************************************************************************
Sub checkusername

strserver = (Serverlist.value)
strusers = (usernametxt.value)
strGroup = (grouptxt.value)
strpassword = (passwordtxt.value)
strlenpassword = Len(strpassword)
strfolders = (foldertxt.value)
strusershare = (foldertxt.value) & "$"



dtStart = TimeValue(Now())
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"

Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection

objCommand.CommandText = _
"<LDAP://dc=wpsdom,dc=local>;(&(objectCategory=User)" & _
"(samAccountName=" & strusers & "));samAccountName;subtree"

Set objRecordSet = objCommand.Execute

If objRecordset.RecordCount = 0 Then
MsgBox strusers & " username does not exist."
Else
MsgBox strusers & " exists."
End If

objConnection.Close




End Sub

</script>


<title>Account Creator</title>
<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
font-size: 36px;
}
.style1 {font-size: 12px}
.style2 {color: #FFFFFF}
-->
</style></head>

<body>
<table width="1001" height="311" border="1" bordercolor="#CCCCCC"
bgcolor="#0099FF">
<tr>
<td width="20" rowspan="8" bordercolor="#0099FF" bgcolor="#0099FF"> </td>
<td height="50" colspan="5" bordercolor="#0099FF" bgcolor="#0099FF"><div
align="center"><u><strong>School Account Creator

</strong></u></div></td>
</tr>
<tr>
<td width="68" bordercolor="#0099FF" bgcolor="#0099FF"><span
class="style1">Forename: </span></td>
<td width="376" bordercolor="#0099FF" bgcolor="#0099FF"><input
name="forenametxt" type="text" size="50" maxlength="50"></td>
<td width="90" bordercolor="#0099FF" bgcolor="#0099FF"><span
class="style1">Surname:</span></td>
<td width="286" bordercolor="#0099FF" bgcolor="#0099FF"><input
name="surnametxt" type="text" size="40" maxlength="50"></td>
<td width="37" rowspan="7" bordercolor="#0099FF" bgcolor="#0099FF"> </td>
</tr>
<tr>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span
class="style1">Username:</span></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><input name="usernametxt"
type="text" id="usernametxt" size="50" maxlength="50">
<input name="checkbutton" type="button" onclick="checkusername"
Title="Click here to check if username exist in Active Directory"
id="checkbutton" value="Check"></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span
class="style1">Password:</span></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><input name="passwordtxt"
type="password" id="passwordtxt" Title="Password to be minimum of 6 chars"
maxlength="14"></td>
</tr>
<tr>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span
class="style1">Group:</span></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><select name="Grouptxt"
class="style1" id="Grouptxt">
<option value="Year99">Year99</option>
<option value="Year00">Year00</option>
<option value="Year01">Year01</option>
<option value="Year02">Year02</option>
<option value="Year03">Year03</option>
<option value="Year04">Year04</option>
<option value="Year05">Year05</option>
<option value="Year06">Year06</option>
<option value="Year07">Year07</option>
<option value="Year08">Year08</option>
<option value="Year09">Year09</option>
<option value="Year10">Year10</option>
<option value="Staff">Staff</option>
</select></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span class="style1">Logon
Script: </span></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span class="style1">
<select size="1" name="logonscripttxt">
<option value="Highsec.bat">Highsec.bat</option>
<option value="Staff.bat">Staff.bat</option>
<option value="High.bat">High.bat</option>
<option value="Adminstrator.bat">Adminstrator.bat</option>
</select>
</span></td>
</tr>
<tr>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span class="style1">Drive
Letter:</span></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span class="style1">
<select name="drivelistmenu">
<option value="M:">M:</option>
<option value="D:">D:</option>
<option value="E:">E:</option>
<option value="F:">F:</option>
<option value="G:">G:</option>
<option value="H:">H:</option>
<option value="I:">I:</option>
<option value="J:">J:</option>
<option value="K:">K:</option>
<option value="L:">L:</option>
<option value="N:">N:</option>
<option value="O:">O:</option>
<option value="P:">P:</option>
<option value="Q:">Q:</option>
<option value="R:">R:</option>
<option value="S:">S:</option>
<option value="T:">T:</option>
<option value="U:">U:</option>
<option value="V:">V:</option>
<option value="W:">W:</option>
<option value="X:">X:</option>
<option value="Y:">Y:</option>
<option value="Z:">Z:</option>
</select>
</span></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><span class="style1">Home
Folder: </span></td>
<td bordercolor="#0099FF" bgcolor="#0099FF"><input name="homedrvtxt"
type="text" Title="\\Servername\Share name" value="\\Server_2\" size="50"
maxlength="50"></td>
</tr>
<tr>
<td bordercolor="#0099FF"><span class="style1">Description:</span></td>
<td bordercolor="#0099FF"><input name="descriptiontxt" type="text"
id="descriptiontxt" value="Type a description here" size="50"
maxlength="50"></td>
<td bordercolor="#0099FF" class="style1">Setup Path </td>
<td bordercolor="#0099FF"><span class="style1">
<input name="foldertxt" type="text" id="foldertxt" Title="Path to
setup home drive." value="" size="40" maxlength="50">
<input type="submit" name="Submit" onclick="browsefor" value="Browse">
</span></td>
</tr>
<tr>
<td bordercolor="#0099FF" class="style1">Server Name: </td>
<td bordercolor="#0099FF" class="style1"><select name="Serverlist"
size="1" id="select">
<option value="Server1">Server1</option>
<option value="Server_2">Server_2</option>
<option value="Server3">Server3</option>
<option value="Server4">Server4</option>
</select></td>
<td bordercolor="#0099FF" bgcolor="#0099FF" class="style1"> </td>
<td bordercolor="#0099FF" bgcolor="#0099FF" class="style1"> </td>
</tr>
<tr>
<td bordercolor="#0099FF"> </td>
<td bordercolor="#0099FF" class="style1"><p align="center"
class="style1"><span class="style2">
<input name="createbutton" type="button" onClick="CreateUserAccount"
id="createbutton" value="Create Account">
</span></p> </td>
<td bordercolor="#0099FF" bgcolor="#0099FF" class="style1"><form
name="form1" method="post" action="">
<div align="center"><u><strong>
<input name="helpbutton" type="button" title="Click here for
assistance" id="helpbutton3" value="Help">
</strong></u> </div>
</form></td>
<td bordercolor="#0099FF" bgcolor="#0099FF" class="style1"><div
align="center"><span class="style2">
<input name="Closebutton" type="Button" onClick="ExitHTA"
id="Closebutton" value="Exit">
</span></div></td>
</tr>
</table>
<!-- WebWriter AutoDato -->Last updated 13.8.2006<!-- WW -->
</body>
</html>


"Liz" wrote:

> How about posting your altered code segment, as well as the value in
> the variables that the error occurs with.
>

Re: passing variables by Tom

Tom
Wed Aug 16 15:29:58 CDT 2006

This line in your createshare routine seems to have a couple of syntax
errors ...

errReturn = objNewShare.Create _
strfolders & "\" & strusers & "," strusershare & "," FILE_SHARE, _
MAXIMUM_CONNECTIONS, "Public share for the Finance group.")


It's missing two ampersands - one after each quoted comma. I believe
it should read ...

errReturn = objNewShare.Create _
strfolders & "\" & strusers & "," & strusershare & "," & FILE_SHARE,
_
MAXIMUM_CONNECTIONS, "Public share for the Finance group.")

Tom Lavedas
============
http://members.cox.net/tglbatch/wsh

Darren wrote:
> Hi Liz
> thx for your response here goes. This is a HTA for use at a
> school i work in. Because we have so many staff and pupils go through the
> school i wanted to design our own user manager that creates the username maps
> the drives and all the other stuff that comes with setting up a user.
> The main problem with this is when i try to concatenate the string variable
> and suffix the share with a $ to hide it on the network also concatenating
> the folder string variable causes me problems as with my other post.
>
> The Sub Routine is called createshare all the other part of the code works
> fine
>
> many thanks
>
> Darren

{snip}

> 'Share Pupil Folder
> '************************************************************************************************
> Sub createshare
>
> strserver = (Serverlist.value)
> strusers = (usernametxt.value)
> strGroup = (grouptxt.value)
> strpassword = (passwordtxt.value)
> strlenpassword = Len(strpassword)
> strfolders = (foldertxt.value)
> strusershare = (foldertxt.value) & "$"
>
> Const FILE_SHARE = 2147483648
> Const MAXIMUM_CONNECTIONS = 0
> strcomputer = "."
> Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
> Set objNewShare = objWMIService.Get("Win32_Share")
>
> errReturn = objNewShare.Create _
> strfolders & "\" & strusers & "," strusershare & "," FILE_SHARE, _
> MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
>
>
> Msgbox errReturn
>
>
>
> End Sub

{snip}

>
> "Liz" wrote:
>
> > How about posting your altered code segment, as well as the value in
> > the variables that the error occurs with.
> >


Re: passing variables by Liz

Liz
Wed Aug 16 15:28:25 CDT 2006

Right off - your HTA's copy is missing the opening "(", and the field
separator "," is missing; you've put them in quotes, making it a string
literal. Try this:

Instead of:

errReturn = objNewShare.Create _
strfolders & "\" & strusers & "," strusershare & "," FILE_SHARE, _
MAXIMUM_CONNECTIONS, "Public share for the Finance group.")

Try:

errReturn = objNewShare.Create ( _
strfolders & "\" & strusers, _
strusershare, _
FILE_SHARE, _
MAXIMUM_CONNECTIONS, _
"Public share for the Finance group." _
)


Re: passing variables by Darren

Darren
Wed Aug 16 17:01:03 CDT 2006

Hi Liz again and thanks for your prompt reply
i copied and pasted the code into my HTA and it does not error but now it
only creates a share called $ and a path to the share called \ so i am not
sure whats going on any more help would be great

Darren

"Liz" wrote:

> Right off - your HTA's copy is missing the opening "(", and the field
> separator "," is missing; you've put them in quotes, making it a string
> literal. Try this:
>
> Instead of:
>
> errReturn = objNewShare.Create _
> strfolders & "\" & strusers & "," strusershare & "," FILE_SHARE, _
> MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
>
> Try:
>
> errReturn = objNewShare.Create ( _
> strfolders & "\" & strusers, _
> strusershare, _
> FILE_SHARE, _
> MAXIMUM_CONNECTIONS, _
> "Public share for the Finance group." _
> )
>
>

Re: passing variables think i might have cracked it by Darren

Darren
Wed Aug 16 17:26:02 CDT 2006

I was refreshing the form before i was making the share routine run now i
have embeded the code from Liz into the main Sub routine it is working.

Many thanks for all your suggestions

Darren

"Tom Lavedas" wrote:

> This line in your createshare routine seems to have a couple of syntax
> errors ...
>
> errReturn = objNewShare.Create _
> strfolders & "\" & strusers & "," strusershare & "," FILE_SHARE, _
> MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
>
>
> It's missing two ampersands - one after each quoted comma. I believe
> it should read ...
>
> errReturn = objNewShare.Create _
> strfolders & "\" & strusers & "," & strusershare & "," & FILE_SHARE,
> _
> MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
>
> Tom Lavedas
> ============
> http://members.cox.net/tglbatch/wsh
>
> Darren wrote:
> > Hi Liz
> > thx for your response here goes. This is a HTA for use at a
> > school i work in. Because we have so many staff and pupils go through the
> > school i wanted to design our own user manager that creates the username maps
> > the drives and all the other stuff that comes with setting up a user.
> > The main problem with this is when i try to concatenate the string variable
> > and suffix the share with a $ to hide it on the network also concatenating
> > the folder string variable causes me problems as with my other post.
> >
> > The Sub Routine is called createshare all the other part of the code works
> > fine
> >
> > many thanks
> >
> > Darren
>
> {snip}
>
> > 'Share Pupil Folder
> > '************************************************************************************************
> > Sub createshare
> >
> > strserver = (Serverlist.value)
> > strusers = (usernametxt.value)
> > strGroup = (grouptxt.value)
> > strpassword = (passwordtxt.value)
> > strlenpassword = Len(strpassword)
> > strfolders = (foldertxt.value)
> > strusershare = (foldertxt.value) & "$"
> >
> > Const FILE_SHARE = 2147483648
> > Const MAXIMUM_CONNECTIONS = 0
> > strcomputer = "."
> > Set objWMIService = GetObject("winmgmts:" _
> > & "{impersonationLevel=impersonate}!\\" & strcomputer & "\root\cimv2")
> > Set objNewShare = objWMIService.Get("Win32_Share")
> >
> > errReturn = objNewShare.Create _
> > strfolders & "\" & strusers & "," strusershare & "," FILE_SHARE, _
> > MAXIMUM_CONNECTIONS, "Public share for the Finance group.")
> >
> >
> > Msgbox errReturn
> >
> >
> >
> > End Sub
>
> {snip}
>
> >
> > "Liz" wrote:
> >
> > > How about posting your altered code segment, as well as the value in
> > > the variables that the error occurs with.
> > >
>
>

Re: passing variables by Liz

Liz
Wed Aug 16 18:20:45 CDT 2006

Just a casual look - add a debug line after you gather your form data
into the variables to ensure that all your variables do have the data
you expected. Second, look at the "strusershare" variable as it looks
like your doing nothing other than adding a "$" to the end of the full
file path and asking Windows to make that the share name, which it
won't do. You probably are looking to code:

strusershare = (usernametxt.value) & "$"

instead.