thunderchicken
asked on
Adding Groups / Permissions to NT User in ASP
Hi folks...
I am writing a web page where an administrator can log on and add/delete/modify users. The creation of a user works fine with the following code....
Dim oDomain, oUser,UserName
set oDomain = GetObject("WinNT://Paperle ss")
UserName = Trim(Request.Form("lblUsr" ))
set oUser = oDomain.Create("User",User Name)
oUser.SetInfo
oUser.SetPassword(Request. Form("lblP W"))
oUser.SetInfo
Response.Write("User added...")
Here's my question (so far)
I need to add the groups to this user that had been created...
lblPW is the user's password (previous form)
lblUsr is the user's login Name (previous form)
I have the main group which is drpLevel (drop box from previous form)
and also a bunch of groups which is C1 (checkboxes previous form)
The adding the users works fine, but they must be in the groups. I put the value in the checkbox on the previous form, but I am having a tough time figuring out how to add them to the groups. I found on a PAQ the following code...
Dim Group as IADsGroup
Set Group = GetObject("WinNT://MyDomai n/Groups/A dministrat ors")
Group.Remove("WinNT://MyDo main/Users /UserA")
Group.Remove("WinNT://MyDo main/Users /UserB")
the error I got was the Dim Group Decloration (error '80005000')
I figure why this didn't work was because I may not have set up the ADSI correctly, or I haven't installed another component. (I replaced the Remove above with Add, but never got to that point with the error on Dim Group line.
I hope that's enough information.
I am writing a web page where an administrator can log on and add/delete/modify users. The creation of a user works fine with the following code....
Dim oDomain, oUser,UserName
set oDomain = GetObject("WinNT://Paperle
UserName = Trim(Request.Form("lblUsr"
set oUser = oDomain.Create("User",User
oUser.SetInfo
oUser.SetPassword(Request.
oUser.SetInfo
Response.Write("User added...")
Here's my question (so far)
I need to add the groups to this user that had been created...
lblPW is the user's password (previous form)
lblUsr is the user's login Name (previous form)
I have the main group which is drpLevel (drop box from previous form)
and also a bunch of groups which is C1 (checkboxes previous form)
The adding the users works fine, but they must be in the groups. I put the value in the checkbox on the previous form, but I am having a tough time figuring out how to add them to the groups. I found on a PAQ the following code...
Dim Group as IADsGroup
Set Group = GetObject("WinNT://MyDomai
Group.Remove("WinNT://MyDo
Group.Remove("WinNT://MyDo
the error I got was the Dim Group Decloration (error '80005000')
I figure why this didn't work was because I may not have set up the ADSI correctly, or I haven't installed another component. (I replaced the Remove above with Add, but never got to that point with the error on Dim Group line.
I hope that's enough information.
ASKER
No, I tried it, and the way my slashes were are fine.
Set oDomain = GetObject("WinNT://YourDom ain")
Set oUser = oDomain.Create ("user", strUser)
Set oGroup = oDomain.GetObject("Group", strGroup)
oGroup.Add ("WinNT://YourDomain/"& strUser)
oUser.SetInfo
If you wanted to add this user to multiple groups, you'd have to step through the set oGroup statment (maybe you can add him to multiple groups at once, not sure, havent tried). I was just about to make a page to do this today actually. I was going to use an array and step through it to add the user to whatever groups they should belong to.
I successfully added the user to a single group using the above code. So i know it works. I just need to modify it now to add to multiple groups.
Set oUser = oDomain.Create ("user", strUser)
Set oGroup = oDomain.GetObject("Group",
oGroup.Add ("WinNT://YourDomain/"& strUser)
oUser.SetInfo
If you wanted to add this user to multiple groups, you'd have to step through the set oGroup statment (maybe you can add him to multiple groups at once, not sure, havent tried). I was just about to make a page to do this today actually. I was going to use an array and step through it to add the user to whatever groups they should belong to.
I successfully added the user to a single group using the above code. So i know it works. I just need to modify it now to add to multiple groups.
ASKER
as long as i can get it to add one group, i'll figure out how to do it... i wont be into the office until Monday, so I'll let you know.... thanks
Dim Group as IADsGroup
"the error I got was the Dim Group Decloration (error '80005000')"
That's because VBScript does not support variable types in variable declarations. Leave the "As" statement.
"the error I got was the Dim Group Decloration (error '80005000')"
That's because VBScript does not support variable types in variable declarations. Leave the "As" statement.
ASKER
With the
Dim Group as IADsGroup
I get this error
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/TechAdmin/UserManager/use rcreated.a sp, line 54
Dim oGroupPath as IADsGroup
---------------^
I tried the above suggestion, but I am wondering if this has anything to do with it. I get an error without the as IADsGroup addon.
Still not working.....
Dim Group as IADsGroup
I get this error
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/TechAdmin/UserManager/use
Dim oGroupPath as IADsGroup
---------------^
I tried the above suggestion, but I am wondering if this has anything to do with it. I get an error without the as IADsGroup addon.
Still not working.....
ASKER
I have to reject this answer for now... it's still not working correctly. I think I need to know how to get the Dim statement to work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so your saying, i don't need to declare those groups at all?
so you are saying that those variables are predefined?
so you are saying that those variables are predefined?
ASKER
Sorry, i figured it out. I kept refreshing the screen and I guess the password didn't submit back over? I don't know and I don't care. It works now, thank you very much for your patience. Stupid small things like that and I have successfully pulled out all of my hair!!!!!!
heh...i know the feeling...that'll be my next project...do it yourself hair plugs ;)p
ASKER
Set Group = GetObject("WinNT:\\MyDomai
Group.Remove("WinNT:\\MyDo
Group.Remove("WinNT:\\MyDo