简体   繁体   English

使用Java以编程方式切换Windows用户帐户?

[英]Programmatically Switch Windows User Accounts using Java?

I have an application written in Java that needs to run under another windows user account each time. 我有一个用Java编写的应用程序,每次都需要在另一个Windows用户帐户下运行。 My question is - is it possible to automatically create and switch windows user accounts using Java? 我的问题是-是否可以使用Java自动创建和切换Windows用户帐户? For example, suppose I create two local user accounts - one called "test12" and one called "test123" and I'm logged in to "test123" - I need to be able to switch to "test12" and then back to "test123" (or a different account) purely using Java. 例如,假设我创建了两个本地用户帐户-一个名为“ test12”,一个名为“ test123”,并且我已登录到“ test123”-我需要能够切换到“ test12”,然后再切换回“ test123” (或其他帐户),完全使用Java。 Is this possible? 这可能吗? How? 怎么样?

I understand there are several question on SO that address this issue however I've only seen the question in C# or .net not in Java (For example, the following question Is it possible to Switch User Accounts programmatically? was asked in C# and the question Create Windows User programmatically c# .net (using PricinpalUser / CreateProfile) was asked in c#) 我知道SO上有几个问题可以解决此问题,但是我只在C#或.net中看到过此问题,而在Java中却没有(例如,以下问题是否可以通过编程方式切换用户帐户?在C#中被问到了问题在C#中以编程方式创建Windows用户c#.net(使用PricinpalUser / CreateProfile

I am using windows 8 however I wanted the application to be able to run on Windows server 12 as well (if possible). 我正在使用Windows 8,但是我希望该应用程序也能够在Windows服务器12上运行(如果可能)。

You should try executing native commands : 您应该尝试执行本机命令:

snippet for doing so : 这样做的代码段:

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 command for running under specific user (might not answer your question but can help you): 在特定用户下运行的Windows命令(可能无法回答您的问题,但可以为您提供帮助):

Navigate to C:\WINDOWS\system32

Enter the following command: runas /user:*computer name\*account name explorer.exe

source : 资源 :

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM