Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a new process with another User Account on Windows?

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.

like image 769
Horcrux7 Avatar asked Dec 12 '08 08:12

Horcrux7


People also ask

How do I make a program run as a different user?

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.

How do I give a program to another user in Windows 10?

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.

How do I run a command prompt in another user?

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.


1 Answers

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).

like image 78
Bananeweizen Avatar answered Nov 15 '22 12:11

Bananeweizen