I’ve spend way to many hours goggling this. Hopefully someone in need this will find this post before wasting 9 hours on figuring out how to do something this simple, like I had too.
Function DisableUser(user As SystemUser) As SystemUser
SetEntityState(user, 1, -1)
Return getEntity(user.LogicalName, "domainname", ConditionOperator.Equal, user.DomainName)
End Function
Function EnableUser(user As SystemUser) As SystemUser
SetEntityState(user, 0, -1)
Return getEntity(user.LogicalName, "domainname", ConditionOperator.Equal, user.DomainName)
End Function
Sub SetEntityState(entity As Entity, state As Integer, Status As Integer)
Dim request As New SetStateRequest
request.EntityMoniker = New EntityReference()
request.EntityMoniker.Id = entity.Id
request.EntityMoniker.LogicalName = entity.LogicalName
request.State = New OptionSetValue(state)
request.Status = New OptionSetValue(Status)
Dim response As SetStateResponse = cliOrganization.Execute(request)
End Sub
SetEntityState(user, 1, -1)
Return getEntity(user.LogicalName, "domainname", ConditionOperator.Equal, user.DomainName)
End Function
Function EnableUser(user As SystemUser) As SystemUser
SetEntityState(user, 0, -1)
Return getEntity(user.LogicalName, "domainname", ConditionOperator.Equal, user.DomainName)
End Function
Sub SetEntityState(entity As Entity, state As Integer, Status As Integer)
Dim request As New SetStateRequest
request.EntityMoniker = New EntityReference()
request.EntityMoniker.Id = entity.Id
request.EntityMoniker.LogicalName = entity.LogicalName
request.State = New OptionSetValue(state)
request.Status = New OptionSetValue(Status)
Dim response As SetStateResponse = cliOrganization.Execute(request)
End Sub
What I did to get to this, was fire up SQL Profiler and look at the SQL being called while disabling and enabling a system user. After messing around inside sdkmessage and sdkmessageproccessingsteps I finally got a few hints and while goggling I stumbles over this page, and gave it a try. And it seemed to work.
Thankyou Sooooooooooooooooooo much.
SvarSletI was unable to activate the account in my program for hours. You are my saviour!!