【问题标题】:Programmatically Switch Windows User Accounts using Java?使用 Java 以编程方式切换 Windows 用户帐户?
【发布时间】:2015-04-12 09:43:10
【问题描述】:

我有一个用 Java 编写的应用程序,每次都需要在另一个 Windows 用户帐户下运行。我的问题是 - 是否可以使用 Java 自动创建和切换 Windows 用户帐户?例如,假设我创建了两个本地用户帐户——一个名为“test12”,一个名为“test123”,我登录到“test123”——我需要能够切换到“test12”,然后再切换回“test123” "(或其他帐户)纯粹使用 Java。这可能吗?怎么样?

我知道关于 SO 有几个问题可以解决这个问题,但是我只在 C# 或 .net 中看到过这个问题,而不是在 Java 中(例如,在 C# 中提出了以下问题 Is it possible to Switch User Accounts programmatically? 和问题 @987654322 @在c#中被问到)

我使用的是 Windows 8,但我希望该应用程序也能够在 Windows Server 12 上运行(如果可能的话)。

【问题讨论】:

    标签: java windows


    【解决方案1】:

    您应该尝试执行本机命令:

    sn-p 这样做:

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

    在特定用户下运行的 Windows 命令(可能无法回答您的问题,但可以帮助您):

    Navigate to C:\WINDOWS\system32
    
    Enter the following command: runas /user:*computer name\*account name explorer.exe
    

    来源:

    Changing windows user in Java

    http://lifehacker.com/290435/switch-user-accounts-from-the-command-prompt

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 2010-11-17
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      相关资源
      最近更新 更多