Hi jaburke,
Here is a sub I have created. It's from my custom pages. This sub in a csp page where the user logs in the CE9. If the user does not exist in CE9, the sub create the user in CE9 and adds him/her to a group and logs the user in CE..
enjoy..
Sub LogonUser( username, password, apsname, authentication, logon_error )
ON ERROR RESUME NEXT
Dim sm
Dim es
Dim ltm
Dim tempRS
'INSTANTIATE INFOSTORE OBJECT FOR SESSION
Set sm = CreateObject("CrystalEnterprise.SessionMgr")
If ( Err.Number <> 0) Then
logon_error = " Problem in creating the Crystal Session Object "
LoginSuccess = FALSE
Exit Sub
End If
Set es = sm.Logon(username, password, apsname, authentication)
'USER NOT FOUND CODE THIS ERROR IS THROWN SO CREATE THE USER IN CE
If (Err.Number =-2147211005 ) Then
Err.Number = 0
'LOGON TO THE SYSTEM AS ADMINISTRATOR
'CREATE THE USER
'ASSIGN TO A GROUP
'LOG OFF THE SYSTEM
Dim IStore
Dim pluginMgr
Dim UserPlugin
Dim NewInfoObjects
Dim InfoObject
Dim NewUser
Dim MemberGroups
' CREATE AN ENTERPRISE MANAGER OBJECT FROM THE SESSIONMANAGER OBJECT with the Administrator user
Set es = sm.Logon ("administrator","admin_password","APS_Name","secEnterprise")
If Err.number <> 0 Then
' the error occurs because Administrator couldn't logon
logon_error = " The new user error:ADMIN RIGHTS. Please contact to Burc Kaya."
LoginSuccess = FALSE
Exit Sub
End If
' CREATE INFOSTORE OBJECT FROM ENTERPRISE SESSION OBJECT
Set IStore = es.Service ("", "InfoStore")
' CREATE A PLUGINMANAGER (THAT MANAGES CRYSTAL OBJECTS)
Set pluginMgr = IStore.PluginManager
' CREATE A USERPLUGIN (THAT MANAGES USER OBJECT)
Set UserPlugin = pluginMgr.PluginInfo("CrystalEnterprise.User")
' CREATE AN INFOSTOREOBJECT (ANY CRYSTAL OBJECT CONTAINER)
Set NewInfoObjects = IStore.NewInfoObjectCollection()
' ADD THE USERPLUGIN TO THE INFOOBJECT
NewInfoObjects.Add(UserPlugin)
' INITIALIZE THE USER OBJECT
Set InfoObject = NewInfoObjects.Item(1)
' CREATE A NEW USER INSTANCE FROM THE USER OBJECT
Set NewUser = InfoObject.PluginInterface("")
' CREATE A MEMBERGROUP INSTANCE FROM THE USER OBJECT
Set MemberGroups = InfoObject.PluginInterface("").Groups
' SET THE USER OBJECT INTO A GROUP BASED ON THE USERTYPE
Select Case usertype
' CHANGE THE NUMBERS TO REFLECT THE GROUPS IN CRYSTAL ENTERPRISE
Case 0,1
MemberGroups.Add(Int(120345))
Case 2
MemberGroups.Add(Int(120376))
Case 3
MemberGroups.Add(Int(120380))
Case 4
MemberGroups.Add(Int(120384))
Case 5
MemberGroups.Add(Int(120388))
Case 6
MemberGroups.Add(Int(120392))
Case 7,8,9
MemberGroups.Add(Int(120396))
End Select
InfoObject.Title = userid
'InfoObject.Description = raises an error here so don't use this line
NewUser.FullName = name
NewUser.PasswordExpires = False
NewUser.AllowChangePassword = False
NewUser.NewPassword = "userpassword"
IStore.Commit (NewInfoObjects)
'Release the Administrator's Enterprise Session
Set es = Nothing
If Err.number <> 0 Then
logon_error = err.description
LoginSuccess = FALSE
Exit Sub
End If
Set es=sm.Logon (userid,"userpassword",defaultaps,defaultaut)
If Err.number <> 0 Then
logon_error = " The new user error: THE USER CANNOT LOGON TO CE. Please contact to Burc Kaya."
LoginSuccess = FALSE
Exit Sub
End If
ElseIf (Err.Number = -2147211006) Then
'THE USER PASSWORD DOES NOT MATCH THE GENERIC PASSWORD ("userpassword")
'CREATE A RESPONSE PAGE HERE
LoginSuccess = FALSE
logon_error = "Crystal user error: THE USER CANNOT LOGON TO CE. Please contact to Administrator." Exit Sub
End If
'Set Session("IStore") = es.Service ("", "InfoStore")
Session("IStore") = es.Service ("", "InfoStore")
If ( Err.Number <> 0) Then
logon_error = "InfoStore Error: USER INFOSTORE CANNOT BE CREATED.(System Error) -ES."
LoginSuccess = FALSE
Exit Sub
End If
LoginSuccess = TRUE
End Sub