簡體   English   中英

使用Java以編程方式切換Windows用戶帳戶?

[英]Programmatically Switch Windows User Accounts using Java?

我有一個用Java編寫的應用程序,每次都需要在另一個Windows用戶帳戶下運行。 我的問題是-是否可以使用Java自動創建和切換Windows用戶帳戶? 例如,假設我創建了兩個本地用戶帳戶-一個名為“ test12”,一個名為“ test123”,並且我已登錄到“ test123”-我需要能夠切換到“ test12”,然后再切換回“ test123” (或其他帳戶),完全使用Java。 這可能嗎? 怎么樣?

我知道SO上有幾個問題可以解決此問題,但是我只在C#或.net中看到過此問題,而在Java中卻沒有(例如,以下問題是否可以通過編程方式切換用戶帳戶?在C#中被問到了問題在C#中以編程方式創建Windows用戶c#.net(使用PricinpalUser / CreateProfile

我正在使用Windows 8,但是我希望該應用程序也能夠在Windows服務器12上運行(如果可能)。

您應該嘗試執行本機命令:

這樣做的代碼段:

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

資源 :

在Java中更改Windows用戶

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