Is it possible to create a new process on windows with a different user account? I know there are a context menu "Run as" but I want do it from Java. I have the username and the password.
The easiest way to run an application under another user is to use the Windows File Explorer GUI. Just find an application (or a shortcut) you want to start, hold the Shift key, and right-click on it. Select Run as different user in the context menu.
Right-click an application in the right pane, and choose Properties. Select the Access Permissions tab. To add user groups, click Add. In the Add/Edit User Group dialog box, navigate to the user group.
You can run cmd by any user and run the command to change the user. *runas /user: press enter. this will prompt you for that user password.
You need to write a DLL using the Java Native Interface (JNI) as you cannot do this with pure Java code.
The DLL itself needs to call the CreateProcessAsUser function to create a process in the context of another user. To successfully create that process you need to provide an access token to the function, which was itself created by calling the LogonUser function (it takes the username and password to authentify that other user).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With