hello Folks,
[Java - Coding time]
- How to get details from current machine in java.
More about JNA:
Java Native Access (JNA)
To use Windows and the domain controller for authentication, we can use native Windows APIs. To call those APIs in Java, we can use the Java Native Access (JNA) library, which you can find on GitHub at
https://github.com/twall/jna and on Maven central:
[Libs]
[Source Code]
/**
*
*/
package thiago.leoncio;
import java.net.UnknownHostException;
import com.sun.jna.platform.win32.Advapi32Util;
import com.sun.jna.platform.win32.Advapi32Util.Account;
/**
* @author THiago
* @Date 06/04/2016
* @Description: How to get details from current machine.
* @libs for JNA(jna.jar;jna-min.jar;jna-platform.jar)
*/
public class MachineDetails {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.getProperty("user.name"); //platform independent
java.net.InetAddress localMachine = null;
try {
localMachine = java.net.InetAddress.getLocalHost();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Hostname of local machine: " + localMachine.getHostName());
System.out.println("UserName logged on your machine:" +System.getProperty("user.name"));
System.out.println("=========== Java Native Access (JNA) details ===========");
for(Account account: Advapi32Util.getCurrentUserGroups()){
System.out.println(account.fqn);
}
}
}
[Output]:
Hostname of local machine: TLEONCIO_LAPTOP
UserName logged on your machine: tleo73638
=========== Java Native Access (JNA) details ===========
WST\domain users
Everyone
BUILTIN\Administrators
BUILTIN\Users
NT AUTHORITY\INTERACTIVE
CONSOLE LOGON
NT AUTHORITY\Authenticated Users
NT AUTHORITY\This Organization