在Java中更改Windows用户 [英] Changing windows user in Java

查看:111
本文介绍了在Java中更改Windows用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Java设置不同的Windows用户?
我有以下问题:

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

我的应用程序以管理员身份执行程序。但是,在一个点,我需要切换Windows用户为了从命令行执行程序(此程序只能由此用户访问 - 我无法启动它作为管理员,由于其许可证)。

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. 以管理员身份启动程序

  2. 以不同的用户身份登录

  3. 通过命令行执行程序

  4. 从用户注销,以管理员身份登录

  5. 继续执行程序直到结束

  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

除了以用户身份登录外,程序在vps服务器上运行。

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

我正在搜索,但找不到正确的解决方案。

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

推荐答案

在Linux中,我们有 su 这个,

In Linux we have su for this,

我不确定窗口,但这个博客似乎这样做。

进一步

这里是从java执行本机命令的代码片段

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) {
}

来源

这篇关于在Java中更改Windows用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆