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

Using vba to set user accounts -"start the following program at logon"

Status
Not open for further replies.

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

 



Justin,

First you state what you did.

Then you post your code.

Then you ask for help, "changing the two mentioned settings ."

Did I miss something?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hi Skip, the code creates user accounts on a windows server machine and assigns the users to groups and sets a number of options like 'allow user to change password' and 'password never expires', these can be seen under 'computer management\users and groups'.

There is also a option to set the startup program for a users account. Basically it is a tick box (start the following program at logon) and text box (Program file name) containing the file name to automatically open when the user logs on to the server.
These are the two items I'm trying to set via code ('start the following program at logon' and 'program file name').
Sorry if I wasn't very clear:)
 





If you are looking for KEYS, check out TAB to get from one control to the next and SPACE to toggle a checkbox.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top