簡體   English   中英

確定活動目錄用戶是否啟動了應用程序

[英]Determine if active directory user started application

我想知道是否以及哪個 Active Directory 用戶啟動了我的 windows java 應用程序。

由於安全原因,我不能使用System.getProperty("user.name") / System.getenv("USERDOMAIN")

Advapi32Util.getUserName()NTSystem.getName()似乎只返回本地用戶,而不是啟動應用程序的活動目錄用戶。

提前致謝

您可以執行 cmd 命令並獲取 output(如果您的安全允許)。

public static String executeCmdCommand(String command) 
{
    String result = null;
    try (var inputStream = Runtime.getRuntime().exec(command).getInputStream();
            var s = new Scanner(inputStream)) 
    {
        result = s.hasNext() ? s.next() : null;
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    }
    return Objects.requireNonNullElse(result, "").trim();
}

然后,executeCmdCommand("whoami") 將返回 "domain/username"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM