On Fri, 25 Aug 2023 07:47:19 GMT, Arno Zeller <[email protected]> wrote:
>> test/jdk/java/lang/ProcessHandle/InfoTest.java line 304:
>>
>>> 302: if (Platform.isWindows() &&
>>> "BUILTIN\\Administrators".equals(whoami)) {
>>> 303: System.out.println("Test seems to be run as
>>> Administrator. " +
>>> 304: "Check for user correctness is not
>>> possible.");
>>
>> Is there an alternative way to determine the expected username?
>> Perhaps by running a windows command or extracting it from the environment
>> (System.getEnv("XX"))?
>
> I think you might use System.getProperty("user.name"). But I am not sure
> about domain names of users on Windows.
> I am also not sure why the user name is currently determined by creating a
> file - there might be a reason for this that is not obvious to me.
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();
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15222#discussion_r1306920852