web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Impersonate another user in X++ code

(0) ShareShare
ReportReport
Posted on by 225

Hello,

I am working on an AX customisation where I need to query user information in AD. I am relying on the following class:

directorySearcher = new System.DirectoryServices.DirectorySearcher(entry);

However, due to the nature of the requirements I would like - in this particular case - for this class to operate under the user credentials of a specific user - not the current AX user.

Is there anyway to achieve this in AX? I.e. instantiate the DirectorySearcher class under the credentials and rights of a different user?


Best regards,

Grzegorz Skrzypczyk

I have the same question (0)
  • Suggested answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Even if that would be possible, you would need to provide the credentials of that user.

    So why not just login to AX with that correct user in the first place? You could let this user set up a batch that runs your code. That way it's executed with this user's identity.

  • Grzegorz Skrzypczyk Profile Picture
    225 on at

    Well I would prefer not to go into the details of the why. Let's say this is to handle an exceptional case which concerns a few users in an organisation counting many thousands. It is either this or a very tedious workaround.

    A batch could work - but ideally we would want this to be in interactive code.

    Storing the credentials is not a problem.

  • Verified answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Look at runAs() function - that's what the system uses in places like in batch and AIF, where there is a global process doing thing on behalf of (and the security context of) actual users.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans