Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Re: Create User Script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3296
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Re: Create User Script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 2 [3] 4 5   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Re: Create User Script - 6/30/2005 1:40:06 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello mate, thanks for taking the time to look at it.

Look for 'This Section will Create The Users Home Drive on \\lnfs01\home$

It should have created the home drive before it runs the script you have just posted. I may be missing something

The Script so far:

<html>
<HTA:APPLICATION
APPLICATIONNAME="Account Creation"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<head>
<title>User Account Creation Form</title>
<style type="text/css">
<!--
.style3 {font-size: 13px}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
.style2 { font-family: Arial, Helvetica, sans-serif;
font-size: 13.5pt;
color: #CC6600;
font-weight: bold;
}
.style5 {font-size: small; color: #FF0000; }
.style6 {color: #FF0000}
-->
</style>

<script type="text/vbscript">

Sub CreateAccount

strUser = TextBox0.Value
If strUser = "" Then
MsgBox "You're missing required fields.",64, "Alert"
Exit Sub
End If

strFirst = TextBox1.Value
If strFirst = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strInitial = TextBox2.Value

strLast = TextBox3.Value
If strLast = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strDisplay = strFirst & ", " & strLast

Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2

' This section will create the user & set part of the General Page.

Set objOU = GetObject("LDAP://OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.Put "userPrincipalName", strUser & "@withers.net"
objUser.SetInfo

objUser.Put "givenName", strFirst

If strInitial <> "" Then
objUser.Put "initials", strInitial
End If

objUser.Put "sn", strLast
objUser.Put "displayName", strDisplay

' This section will assign the user a standard password

objUser.SetPassword "Passw0rd"
objUser.Put "pwdLastSet", 0

intUAC = objUser.Get("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then
objUser.Put"userAccountControl", intUAC Xor ADS_UF_ACCOUNTDISABLE
End If
objUser.SetInfo

' Address Page Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "streetAddress", "16 Old Bailey"
objUser.Put "l", "London"
objUser.Put "postalCode", "EC4M 7EG"
objUser.Put "c", "GB"
objUser.SetInfo

' General Page Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "physicalDeliveryOfficeName", "London"
objUser.Put "telephoneNumber", "+44 (0)20 7597"
objUser.Put "mail", "@withersworldwide.com"
objUser.Put "wWWHomePage", "http://www.withersworldwide.com"
objUser.SetInfo

' Users Telephone Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "facsimileTelephoneNumber", "+44 (0)20 7597 6543"
objUser.SetInfo

' Organization Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "department", "Family Department"
objUser.Put "company", "Withers LLP"
objUser.SetInfo

'This Section Will Add the user to the standard Security Groups

Const ADS_PROPERTY_APPEND = 3

Set objGroup = GetObject _
("LDAP://cn=LN London Users,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

Set objGroup = GetObject _
("LDAP://cn=LN Family,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

(in reply to cjwallace)
 
 
Post #: 41
 
 Re: Create User Script - 6/30/2005 1:43:57 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
What is the ? It is most likely causing something to error out. Remove it and try again.

strDest = "\\LNFS01\home$\" & strUser
objShell.Run ("SetACL.exe -on """ & strDest & """ -ot file -actn ace " & "-ace ""n:WITHERS\" & strUser & ";p:change""")

(in reply to cjwallace)
 
 
Post #: 42
 
 Re: Create User Script - 6/30/2005 1:45:17 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Sorry mate, when i put the post up i was going to make the section bold for you is bold on this board. i quickly went in and changed the post but you must have already been reading it.

That is not in my script by default.

(in reply to cjwallace)
 
 
Post #: 43
 
 Re: Create User Script - 6/30/2005 1:46:03 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
Ah. Let me keep looking then.

(in reply to cjwallace)
 
 
Post #: 44
 
 Re: Create User Script - 6/30/2005 1:48:25 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Thanks mate. i really appreciate your help....Thank you

(in reply to cjwallace)
 
 
Post #: 45
 
 Re: Create User Script - 6/30/2005 1:56:48 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
I removed some quotes from places like when you create the dir after the username. It may not matter, but I took that section of code and modified it so I can create a dir and ACL it on one of my shares and it worked.



<html>
<HTA:APPLICATION
APPLICATIONNAME="Account Creation"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>
<head>
<title>User Account Creation Form</title>
<style type="text/css">
<!--
.style3 {font-size: 13px}
body,td,th {
font-family: Arial, Helvetica, sans-serif;
}
.style2 { font-family: Arial, Helvetica, sans-serif;
font-size: 13.5pt;
color: #CC6600;
font-weight: bold;
}
.style5 {font-size: small; color: #FF0000; }
.style6 {color: #FF0000}
-->
</style>

<script type="text/vbscript">

Sub CreateAccount

strUser = TextBox0.Value
If strUser = "" Then
MsgBox "You're missing required fields.",64, "Alert"
Exit Sub
End If

strFirst = TextBox1.Value
If strFirst = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strInitial = TextBox2.Value

strLast = TextBox3.Value
If strLast = "" Then
MsgBox "You're missing required fields",64, "Alert"
Exit Sub
End If

strDisplay = strFirst & ", " & strLast

Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2

' This section will create the user & set part of the General Page.

Set objOU = GetObject("LDAP://OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.Put "userPrincipalName", strUser & "@withers.net"
objUser.SetInfo

objUser.Put "givenName", strFirst

If strInitial <> "" Then
objUser.Put "initials", strInitial
End If

objUser.Put "sn", strLast
objUser.Put "displayName", strDisplay

' This section will assign the user a standard password

objUser.SetPassword "Passw0rd"
objUser.Put "pwdLastSet", 0

intUAC = objUser.Get("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then
objUser.Put"userAccountControl", intUAC Xor ADS_UF_ACCOUNTDISABLE
End If
objUser.SetInfo

' Address Page Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "streetAddress", "16 Old Bailey"
objUser.Put "l", "London"
objUser.Put "postalCode", "EC4M 7EG"
objUser.Put "c", "GB"
objUser.SetInfo

' General Page Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "physicalDeliveryOfficeName", "London"
objUser.Put "telephoneNumber", "+44 (0)20 7597"
objUser.Put "mail", "@withersworldwide.com"
objUser.Put "wWWHomePage", "http://www.withersworldwide.com"
objUser.SetInfo

' Users Telephone Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "facsimileTelephoneNumber", "+44 (0)20 7597 6543"
objUser.SetInfo

' Organization Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

objUser.Put "department", "Family Department"
objUser.Put "company", "Withers LLP"
objUser.SetInfo

'This Section Will Add the user to the standard Security Groups

Const ADS_PROPERTY_APPEND = 3

Set objGroup = GetObject _
("LDAP://cn=LN London Users,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

Set objGroup = GetObject _
("LDAP://cn=LN Family,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

Set objGroup = GetObject _
("LDAP://cn=LN GWArchive,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.PutEx ADS_PROPERTY_APPEND, _
"member", Array("cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")
objGroup.SetInfo

' Users Home & Profile Information

Set objUser = GetObject _
("LDAP://cn=" & strUser & ",OU=FAMILY,OU=LONDON USERS,OU=WITHERS USERS,dc=withers,dc=net")

(in reply to cjwallace)
 
 
Post #: 46
 
 Re: Create User Script - 6/30/2005 1:58:37 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Ok i will give this a go now. Will report back in two mins

Thanks

(in reply to cjwallace)
 
 
Post #: 47
 
 Re: Create User Script - 6/30/2005 2:03:35 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello mate. sorry to say the changes you have made have not worked.

Any other ideas on how i might do it with this script or passing the variable to another script to change the permissions?

Thanks for your help and time

(in reply to cjwallace)
 
 
Post #: 48
 
 Re: Create User Script - 6/30/2005 2:07:33 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
So "\\LNFS01\home$\" & strUser does not have the correct permissions, but the user and folder do exist correct?

Also, you do not need to add this more than once in a sub:

Set objFSO = CreateObject("Scripting.FileSystemObject")

(in reply to cjwallace)
 
 
Post #: 49
 
 Re: Create User Script - 6/30/2005 2:11:23 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello mate. Yes the script creates the user and creates the folder which are both there. The permissions for the home folder are correct but i would like to get the script to add the user to the ntfs permissions list. When you manually do it through AD, AD gives the user full control to the home drive.

Do you think the script needs to wait for a bit before it changes the permissions?

(in reply to cjwallace)
 
 
Post #: 50
 
 Re: Create User Script - 6/30/2005 2:13:19 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
If you right click the folder and go to Security, do you see the user there? That is what SetACL does. It gives the user NTFS rights.

Please explain what you are trying to do with AD? If the home folder has the correct permissions then the script is working correctly.

(in reply to cjwallace)
 
 
Post #: 51
 
 Re: Create User Script - 6/30/2005 2:16:31 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello mate, no after the script has run, if i go to the users home drive and right click and goto security the user is not in the NTFS list. The only users and groups are that in the list are the ones that the directory is inheriting from its parent.

All i really want to do is add the user to the list on the NTFS security tab.

Many thanks

(in reply to cjwallace)
 
 
Post #: 52
 
 Re: Create User Script - 6/30/2005 2:19:47 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
hmmmm. this should do it, but perhaps try putting in a wscript.sleep for 5 seconds or so.

Also, you should remove your duplicate Set objFSO = CreateObject("Scripting.FileSystemObject") that I see in your script.

(in reply to cjwallace)
 
 
Post #: 53
 
 Re: Create User Script - 6/30/2005 2:41:05 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hello mate. I have changed the bit of code to:

'This Section will Create The Users Home Drive on \\lnfs01\home$

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder("\\LNFS01\home$\" & strUser)

SecondsToDelay = "5"
WScript.Sleep(SecondsToDelay * 5000)

Set objShell = CreateObject("Wscript.Shell")

strDest = "\\LNFS01\home$\" & strUser
objShell.Run ("SetACL.exe -on """ & strDest & """ -ot file -actn ace " & "-ace ""n:WITHERS\" & strUser & ";p:change""")


But when i run the code i get

Line: 165

Char: 5

Error: Object required 'WScript'

Huuuuuuum not sure whats going on

(in reply to cjwallace)
 
 
Post #: 54
 
 Re: Create User Script - 6/30/2005 3:34:45 AM   
  ExHorn04

 

Posts: 4
Score: 0
Joined: 6/8/2005
From: USA
Status: offline
I am attempting to use your HTA application for the user adding to active directory but I am continuously getting a error that states:

Line: 75
Char: 1
Error: There is no such object on the server.
Code: 0

I am very new to vbscript so I am no sure what is wrong with my script.

This is the script:

objConnection.Close

Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_PROPERTY_UPDATE = 2

Set objOU=GetObject("LDAP://OU=Exchange,OU=Employees,dc=atfcu,dc=org")
Set objUser = objOU.Create("User", "cn=" & strUser)
objUser.Put "sAMAccountName", LCase(strUser)
objUser.SetInfo

Active Directory is currently set up as:

DC=atfcu.org -> OU=Exchange -> OU=Employees (all of the employees are located in the Employees unit.)

Can you please point me in the right direction? What should be the correct order for the LDAP designation?

For example ("LDAP://OU=Exchange,OU=Employees,dc=atfcu,dc=org")
Is that correct for what I am attempting to do?

Thanks guys.

Chris

(in reply to cjwallace)
 
 
Post #: 55
 
 Re: Create User Script - 6/30/2005 3:55:35 AM   
  ExHorn04

 

Posts: 4
Score: 0
Joined: 6/8/2005
From: USA
Status: offline
I think my organization unit may be too deep, I can add to the exchange OU, but not to the employees OU.

(in reply to cjwallace)
 
 
Post #: 56
 
 Re: Create User Script - 6/30/2005 5:29:17 AM   
  jraisor

 

Posts: 39
Score: 0
Joined: 4/29/2005
From:
Status: offline
getting 2 errors
Say the following is a syntax error
########################
Sub bodyLoaded()
window.ResizeTo 330,585 ' WIDTH, HEIGHT
End Sub
########################
and getting another error that says:
type mismatch "bodyLoaded"

(in reply to cjwallace)
 
 
Post #: 57
 
 Re: Create User Script - 6/30/2005 6:05:13 AM   
  Bezerk

 

Posts: 22
Score: 0
Joined: 6/20/2005
From: Netherlands
Status: offline
Hi,

I have a script that i am currently working on that work very well, easy to customize. I have seen an example on www.computerperformance.co.uk and toke that as my
[code]

SECTION A DECLARE VARIABLES

Option Explicit
' Objects declared :
Dim objRootDSE, objFSO, objShell
Dim objUser, objGroup, objContainer
Dim objExcel, objSheet

Dim objExcelFile

' Strings declared :
Dim strCN, strNTSam, strPWD, strOUContainer, strUPN, strEnable
Dim strGroupDN, strLast, strFirst, strDescription, strGroup

Dim strHomeFolder, strHomeDrive
Dim strNetBIOSDomain, strDomain

' Integers declared :
Dim intNumusers, intRunError, intRow, intCol

'Declare Constants:
objExcelFile = "C:\scripts\addusers.xls"
strPWD = "Welkom01"

'SECTION B CONNECT TO ACTIVE DIRECTORY
' Get Domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")

'Section C OPEN AND READ THE SPREADSHEET
' Connect to spreadsheet where users are stored
Set objExcel = CreateObject("Excel.Application")

' Open the Speadsheet (Error Handling Section).
On Error Resume Next
Err.Clear
objExcel.Workbooks.Open objExcelFile
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Wscript.Echo "Kan de file niet vinden!" & Space(2) & objExcelFile
Wscript.Quit
End If
On Error GoTo 0
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

' SECTION F DO LOOP UNTIL EMPTY CELL IN SPREADSHEET
'start at row 2 first row is for headlines
intRow = 2

Do
' Read values from spreadsheet for this user.
strCN = Trim(objSheet.Cells(intRow, 1).Value)
strNTSam = Trim(objSheet.Cells(intRow, 2).Value)
strOUContainer = Trim(objSheet.Cells(intRow, 3).Value)
strFirst = Trim(objSheet.Cells(intRow, 4).Value)
strLast = Trim(objSheet.Cells(intRow, 5).Value)
strUPN = Trim(objSheet.Cells(intRow, 6).Value)
strHomeFolder = Trim(objSheet.Cells(intRow, 7).Value)
strHomeDrive = Trim(objSheet.Cells(intRow, 8).Value)
strEnable = Trim(objSheet.Cells(intRow, 9).Value)
strDescription = Trim(objSheet.Cells(intRow, 10).Value)
strGroup = Trim(objSheet.Cells(intRow, 12).Value)

'extra section for error handling
' Connect to OU where users to be created.
On Error Resume Next
Err.Clear
Set objContainer = GetObject("LDAP://" & strOUContainer)

If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Wscript.Echo "Edit the LDAP path to your OU " & strOUContainer
Wscript.Quit
End If
On Error GoTo 0



'SECTION D CREATE THE USER
On Error Resume Next
Err.Clear
Set objUser = objContainer.Create("user", "cn=" & strCN)
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Wscript.Echo "Cannot create user with cn: " & strCN
Else
On Error GoTo 0
' Assign mandatory attributes cn and sAMAccountName.
If strNTSam = "" Then
strNTSam = strCN
End If
objUser.sAMAccountName = strNTSam
On Error Resume Next
Err.Clear
objUser.SetInfo
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Wscript.Echo "Unable to create user with NT SAM name: " & strNTSam
Else
' Set password for user.
objUser.SetPassword strPWD
If Err.Number <> 0 Then
Err.Clear
On Error GoTo 0
Wscript.Echo "Unable to set password for user " & strNTSam
End If
On Error GoTo 0
' Enable the user account.
objUser.AccountDisabled = False
If strFirst <> "" Then
objUser.givenName = strFirst
End If

' Assign values to remaining attributes.
If strLast <> "" Then
objUser.sn = strLast
End If
If strUPN <> "" Then

(in reply to cjwallace)
 
 
Post #: 58
 
 Re: Create User Script - 6/30/2005 6:25:01 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
cjwallace,

Ah yeah. Sorry, you can't use a Wscript.Sleep in an HTA or HTML App. Sorry about that. I have been thinking about it and would like you to just run setacl on your own from a command prompt with the appropriate parameters to see if you get any errors.

Example:

SetACL.exe -on "C:\my dir" -ot file -actn ace -ace "n:domain1\user1;p:change"

(in reply to cjwallace)
 
 
Post #: 59
 
 Re: Create User Script - 6/30/2005 6:26:05 AM   
  esnmb

 

Posts: 441
Score: 0
Joined: 1/11/2005
From: USA
Status: offline
you must not have a sub called bodyloaded.

(in reply to cjwallace)
 
 
Post #: 60
 
 
Page:  <<   < prev  1 2 [3] 4 5   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Re: Create User Script Page: <<   < prev  1 2 [3] 4 5   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts