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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Get temporal folder from a specific user

(0) ShareShare
ReportReport
Posted on by 1,875

Hi

Anyone know how to get temporal user folder for a specific user?

If I use it

System.IO.Path::GetTempPath();
WinAPI::getTempPath();

return tmp folder from current user.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    How about combining WinAPI::getTempPath with RunAs() to impersonate the user?

    https://msdn.microsoft.com/en-us/library/aa893873.aspx

  • Mea_ Profile Picture
    60,286 on at

    @Vilmos Kintera

    And he will probably get folder of AOS user because all code in runAs is executed in CIL and you have to run runAs on server tier...

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    You are correct, runAs does require server-side execution.

    Javier, you could get the SID of the user account you want to get the temp path for from the UserInfo.SID table/field.

    Then you could access the Registry key under HKEY_USERS\SID\Environment under which there is either a TMP or Temp expandable string value, holding the temp folder for the user you are interested in.

    Here is an example of how to handle registry in AX (this is very old, you should probably use .Net namespaces to do it in a more modern way):

    https://fredshen.wordpress.com/2006/03/16/read-and-alter-registry-settings-in-axapta/

  • XB Profile Picture
    1,875 on at

    I'm getting an error

    static void main(Args _a)
    {
    RunAsPermission perm;
    UserId runAsUser;
    SysUserInfo userInfo;
    container con;

    userInfo = SysUserInfo::find();
    runAsUser = userInfo.Id;
    perm = new RunAsPermission(runAsUser);
    perm.assert();

    con = runAs(runAsUser, classnum(test), staticMethodStr(Test, testmethod));

    info(conPeek(con,1));

    CodeAccessPermission::revertAssert();
    }

    static container testmethod()
    {
    return [WinApiServer::getTempPath()];
    }

    Microsoft.Dynamics.Ax.Xpp.ErrorException: Exception of type 'Microsoft.Dynamics.Ax.Xpp.ErrorException' was thrown.
    at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue)
    at Microsoft.Dynamics.Ax.MSIL.Interop.ThrowCQLFuncError(IL_CQL_ERR cqlErr, String typeName, String methodName)
    at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)
    at Microsoft.Dynamics.Ax.Xpp.PredefinedFunctions.runAsInvoke(String className, String staticMethodName, Object[] parms, Object[]& exportInfolog)

  • XB Profile Picture
    1,875 on at

    ok Vilmos Kintera

    I'll check it

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    That should work, however do not forget that if it has a Windows path reference like %USERPROFILE% that will replace as your user account.

    I think the userprofile value sits under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\SID\ProfileImagePath, see if that works - or you might want to google this if that does not look right.

  • Mea_ Profile Picture
    60,286 on at

    Why are doing this at all ? Because if you have a user in AX it does not mean that this user will have a folder on same workstation as you running AX client, so you will receive nothing. Second thing is security you may won't have access to users folder as well.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans