Get SID of windows user using X++ in Dynamics AX

Description:-

I was just wondering if there is any way to get the security Id [SID] of windows users. Sometimes knowing SID of system is very much helpful specially when the user in the database has been deleted or database is migrated/upgraded incorrectly. Of course, we can get the SID’s easily from the system by opening registry editor and selecting HKEY_USERS in left pane to expand it, in left pane itself you will find the SID of users. But, below is the simple code to get the SID’s of windows users using X++ Code.

Note:- xAxaptaUserManager class – getuserId() also helps to get SID.

Code:-

static void SR_GetUserSID(Args _args)
{
  str windowsUser = 'companyDomain\\umesh.patel'; 
  networkALias alias;
  networkDomain domain;
  int pos, len;
  sid userSid;
  Microsoft.Dynamics.IntegrationFramework.Utilutil;
  #Aif
  #File
  ;
  //Split the windowsUser into domain and alias
  len = strlen(windowsUser);
  pos = strfind(windowsUser, #FilePathDelimiter, 1,len);
  domain = substr(windowsUser, 1, pos-1);
  alias = substr(windowsUser, pos+1, len-pos);

  new InteropPermission(InteropKind::ClrInterop).assert();
  // BP Deviation Documented
  util = newMicrosoft.Dynamics.IntegrationFramework.Util();

  //Get the Windows SID for this user
  // BP Deviation Documented
  userSid = util.GetUserSid(domain, alias);
  CodeAccessPermission::revertAssert();

  info(userSid);
}

Related Posts

Previous
Next Post »

Thanks for comments.....