On Tue, 29 Aug 2023 08:30:10 GMT, Christoph Langer <clan...@openjdk.org> wrote:

>> It seems that ProcessHandle.info()  returns **DOMAIN/USERNAME** on Windows 
>> but System.getProperty("user.name") only the **USERNAME**.
>> You can get **DOMAIN** and **USERNAME** on **Windows** by calling:
>> com.sun.security.auth.module.NTSystem NTSystem = new 
>> com.sun.security.auth.module.NTSystem();
>> String user = NTSystem.getName();
>> String domain = NTSystem.getDomain();
>
> Yes, I think using System.getProperty("user.name") is brittle as well. If 
> we'd use `com.sun.security.auth.module.NTSystem`, we would introduce the 
> dependency to another module - `jdk.security.auth`. Not sure, whether this is 
> a good option.

The system environment has the domainname and the username.

String username = (System.getenv("USERDOMAIN") + "/" + 
System.getenv("USERNAME")).toLowerCase(Locale.ROOT);

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15222#discussion_r1310499879

Reply via email to