B4J Question How to check from B4J code if user login performed?

amorosik

Expert
Licensed User
I have a program X that I start, in Windows 10 pro, via task scheduler when the operating system starts
So the program starts and runs before any user has logged in
Then it can happen that an operator arrives and performs the user login on his desktop and starts working
How to use internal code in the X program to recognize the fact that a user has logged in?
 

Chris2

Active Member
Licensed User
Longtime User
You can use the following to get the the name of a logged in user:
B4X:
Dim jo As JavaObject
jo.InitializeStatic("java.lang.System")
Dim m As Map = jo.RunMethod("getProperties", Null)
Log(m.get("user.name"))
I've not tested it in this way but perhaps it will return an empty string or Null object if no one is logged in?

*My knowledge of JavaObject is exceedingly limited. The code above was arrived at through trial and error based on:
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Note: System.getProperty("user.name") will only work if the user launches the application. If the program is run by System or an application like LANDesk, then the user will come out as "SYSTEM" (under domain "NT AUTHORITY").


This is probably worth to check with inlinejava.

B4X:
 com.sun.security.auth.module.NTSystem NTSystem = new
          com.sun.security.auth.module.NTSystem();
  System.out.println(NTSystem.getName());
  System.out.println(NTSystem.getDomain())


Ref: https://stackoverflow.com/questions/725124/detect-user-logged-on-a-computer-using-java
 
Upvote 0
Top