juddymarch
Technical User
- Aug 10, 2007
- 17
Hi I had a previous thread to create users accounts and assign them to groups on Windows Server. I have managed to achieve almost everything bar setting up the "start the following program at logon" and "Program file name" option under the Environment tab, which is one of the most important settings for me.
My code is as follows:
On Error GoTo Err_ErrorCheck
Dim Container
Dim ContainerName
Dim User
Dim NewUser
Dim Group1
Dim Group2
'------------------------------------
'CREATE NEW USER ACCOUNT
ContainerName = "servername"
NewUser = Me.txtDatabaseAllocated ' new user to be created
Set Container = GetObject("WinNT://" & ContainerName)
Set User = Container.Create("User", NewUser)
Call GenerateLogin 'GENERATES A RANDOM PASSWORD FOR NEW ACCOUNT
User.FullName = Me.txtCompanyName
User.Description = Nz(Me.tabInstall_cboIndustry.Column(1), "") & " " & Nz(Me.cboState, "")
User.setpassword strOrganisationPassword
Me.txtDatabaseID = strOrganisationPassword
'user.put("PasswordExpired",
User.SetInfo
'-------------------------------------
'ASSIGN USER TO DIFFERENT GROUPS
Set Group1 = GetObject("WinNT://" & ContainerName & "/" & "Users")
Group1.Add (User.ADsPath)
Set Group2 = GetObject("WinNT://" & ContainerName & "/" & "Remote Desktop Users")
Group2.Add (User.ADsPath)
'----------------------------------------------
'CHANGE OPTIONS ON USER ACCOUNT
'CANT CHANGE PASSWORD
Const UF_PASSWORD_CANT_CHANGE = &H40
User.Put "userFlags", User.Get("UserFlags") Or UF_PASSWORD_CANT_CHANGE
'PASSWORD DOESN'T EXPIRE
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
User.Put "userFlags", User.Get("UserFlags") Or ADS_UF_DONT_EXPIRE_PASSWD
User.SetInfo
MsgBox "A new user account has been created for: " & Me.txtDatabaseAllocated & vbCrLf & "With the password: " & CStr(Me.txtDatabaseID) & vbCrLf & "You will need to login into this account to set up system files. Then logout and click the 'Create Organisation' button to complete the process!", , "Attention!"
'---------------------------------------
Exit_ErrorCheck:
Exit Sub
Err_ErrorCheck:
MsgBox Err.Description
Resume Exit_ErrorCheck
Any help would be greatly appreciated in changing the two mentioned settings as I am rather desperate as the rest of what I have done is pointless if I cant change these.
Thanks
Justin
My code is as follows:
On Error GoTo Err_ErrorCheck
Dim Container
Dim ContainerName
Dim User
Dim NewUser
Dim Group1
Dim Group2
'------------------------------------
'CREATE NEW USER ACCOUNT
ContainerName = "servername"
NewUser = Me.txtDatabaseAllocated ' new user to be created
Set Container = GetObject("WinNT://" & ContainerName)
Set User = Container.Create("User", NewUser)
Call GenerateLogin 'GENERATES A RANDOM PASSWORD FOR NEW ACCOUNT
User.FullName = Me.txtCompanyName
User.Description = Nz(Me.tabInstall_cboIndustry.Column(1), "") & " " & Nz(Me.cboState, "")
User.setpassword strOrganisationPassword
Me.txtDatabaseID = strOrganisationPassword
'user.put("PasswordExpired",
User.SetInfo
'-------------------------------------
'ASSIGN USER TO DIFFERENT GROUPS
Set Group1 = GetObject("WinNT://" & ContainerName & "/" & "Users")
Group1.Add (User.ADsPath)
Set Group2 = GetObject("WinNT://" & ContainerName & "/" & "Remote Desktop Users")
Group2.Add (User.ADsPath)
'----------------------------------------------
'CHANGE OPTIONS ON USER ACCOUNT
'CANT CHANGE PASSWORD
Const UF_PASSWORD_CANT_CHANGE = &H40
User.Put "userFlags", User.Get("UserFlags") Or UF_PASSWORD_CANT_CHANGE
'PASSWORD DOESN'T EXPIRE
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000
User.Put "userFlags", User.Get("UserFlags") Or ADS_UF_DONT_EXPIRE_PASSWD
User.SetInfo
MsgBox "A new user account has been created for: " & Me.txtDatabaseAllocated & vbCrLf & "With the password: " & CStr(Me.txtDatabaseID) & vbCrLf & "You will need to login into this account to set up system files. Then logout and click the 'Create Organisation' button to complete the process!", , "Attention!"
'---------------------------------------
Exit_ErrorCheck:
Exit Sub
Err_ErrorCheck:
MsgBox Err.Description
Resume Exit_ErrorCheck
Any help would be greatly appreciated in changing the two mentioned settings as I am rather desperate as the rest of what I have done is pointless if I cant change these.
Thanks
Justin