Is there a way to detect when user opens a new program

  android-activity, java, windows

I am trying to make a activity tracker for personal use in Java, Wich should detect any program a PC user opens and log it into a text file with a timestamp, but the best thing I found was about detecting other jar’s then it would detect activity but Im stuck at tracking the Program being used

Actually detecting Wich program is on focus would also be good

Source: Windows Questions