We are using createProcessAsUser function to create a child process running in the context of logged in/Impersonated user using waffle and JNA libraries.
But we need to load the user profile after the impersonation, but the LoadUserProfile function is not available in a JNA library.
As we found that CreateProcessWithTokenW is capable of loading the user profile. But this function also not available in the JNA/Waffle library.
Could anyone help us how to load the user profile or how to use the CreateProcessWithTokenW in Java application.
To use
CreateProcessWithTokenWfrom java with JNA you need to bind the function. JNA is just a layer, that makes it possible to call directly native library functions. For this to work JNA uses java descriptions of the native interface, which are then used to do the actual call.The jna-platform contrib project (released together with the main project) contains a big number of already bound win32 functions and indeed in
Advapi32.javathere are already bindings forCreateProcessAsUserandCreateProcessWithLogonW. Based on that I would try this (UNTESTED!):This assumes that you run with the system property
w32.asciiset tofalseor unset, which is the recommend setup. In that case theW32APIFunctionMapper.UNICODEis used, which appends the "W" suffix automatically. The then also selectedW32APITypeMapper.UNICODEensures, that javaStringobjects are mapped towcharsor in case of a function call toLP*WSTR.