Changing windows user in Java

随声附和 提交于 2019-12-31 05:31:07

问题


Is it possible to set a different windows user with Java? I have following issue:

My application executes written program as admin. However, at one point I need to switch windows user in order to execute program from the command line (this program can only be accessed by this user - I cannot start it as admin due to its license).

So to simplify explanation i need to do following things:

  1. start program as admin
  2. login at one point as different user
  3. execute program from command line
  4. logout from user, login as admin
  5. continue to execute program till the end

I did everything except logged in as user. Program runs on vps server.

I was googling but couldn't find the right solution.


回答1:


In Linux we have su for this,

I am not sure about windows but this blog seems doing it.

further

here is code snippet to execute native commands from java

try {
    // Execute a command without arguments
    String command = "dir";
    Process child = Runtime.getRuntime().exec(command);

    // Execute a command with an argument
    command = "dir";
    child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}

Source



来源:https://stackoverflow.com/questions/4183438/changing-windows-user-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!