Notifications
Announcements
No record found.
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
How about combining WinAPI::getTempPath with RunAs() to impersonate the user?
https://msdn.microsoft.com/en-us/library/aa893873.aspx
@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...
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/
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)
ok Vilmos Kintera
I'll check it
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.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 4 Most Valuable Professional
Priya_K 4
MyDynamicsNAV 2