1

I need to write a program which executes

whenever some one logged In to the windows system.

It is for daily report generation purpose.

I have written the program but couldn't get how to execute it on user login.

All the help would really be appreciated.

EDIT most of the people suggesting that I should put file in startup folder, but startup files only execute if 'system started/restarted'... I need to run the program whenever a user login like if the computer is started but locked and then someone unlocks, this program should be executed.

Correct me if I am wrong.

Just_another_developer
  • 4,907
  • 12
  • 41
  • 75
  • So...something like an application that starts up when the user is logged in? – Makoto Mar 21 '14 at 04:03
  • make an executable and put it in startup folder if it is windows platform... – Sambhav Mar 21 '14 at 04:04
  • yes.It is a simple desktop program that I need to run. – Just_another_developer Mar 21 '14 at 04:04
  • No @Sambhav ,OP is asking about run the program at the time of user login not window startup. – JDGuide Mar 21 '14 at 04:05
  • You can create a windows service and run it on startup, google it. Too bad I have a Mac. Reference [here](http://ethertubes.com/make-a-program-run-as-a-windows-service-on-boot/) – Puru-- Mar 21 '14 at 04:05
  • but startup files only execute if 'system started/restarted'... I need to run the program whenever a user login like if the computer is started but locked and then someone unlocks, this program should be executed. – Just_another_developer Mar 21 '14 at 04:06
  • The fact that it's java is sorta irrelevant; the real question is how to launch *anything* when the user logs in. It's certainly possible; I have several apps that I configured that way and others configured themselves to do it... but I'm not sure how to automate setting that up. – keshlam Mar 21 '14 at 04:07
  • You can make services run when you login, follow my advise :-) – Puru-- Mar 21 '14 at 04:08
  • @Puru-- I am trying to follow your advise but since I have never done this before I am having difficulties, along with your provided link I have googled a lot to make a java application a Window Service but only got further confused, could you please tell me in simple steps how to convert a simple Java program in a windows Service? All the help would really be appreciated. – Just_another_developer Apr 17 '14 at 12:23
  • @HappyDev have you tried [this](http://edn.embarcadero.com/article/32068)? – Puru-- Apr 17 '14 at 17:36
  • @Puru-- Yes, I googled a lot and tried to create a service from a Java Program, but quite didnt get the articles and failed to create a service... If you could please just put in simple steps what to do, it would be a great help.. – Just_another_developer Apr 18 '14 at 04:46

5 Answers5

2

If you are working on a Windows OS then you can create an executable jar file of your java. In order to make it launch at login you need to include it to the windows startup list. You can create a batch file (.bat) in which you put:

"<YOUR PATH TO JAVA>/javaw" -jar "YourJar.jar"

Add this .bat file to windows startup check this

Batch/CMD: Adding files to Startup list

Hope it helps !

Community
  • 1
  • 1
Braza
  • 415
  • 4
  • 15
1

Setup your java application to run as a windows service.I think this answer will help you.

Answer is here

Community
  • 1
  • 1
JDGuide
  • 5,759
  • 11
  • 39
  • 53
1

Create a batch program and put it on startup that should start your target file to run what you want to do.....

batch code :

start java target.java

Must setup the path for startup b4 run....

Muthu
  • 57
  • 3
1

@happy Dev: hope you already know how to make a .bat in windows, just create a bat file which has line to execute java. or for more help on this you can see:

http://introcs.cs.princeton.edu/java/15inout/windows-cmd.html

Just make sure you have java installed on that machine. and your environment variable is set for java other wise you have to provide the complete java bin path.

Regarding how to run on login. simple way to go:

for windows 7: start menu--> All programs--> find a folder name startup and right click on it. there you can see open for all users open it and place your file there. every time when some user login the bat file will be executed automatically. and remember this wont work on hibernate. or to open that location you can just go to:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

for Other OS path is almost similar with just a minor difference.

Adeel Ahmad
  • 1,511
  • 1
  • 15
  • 20
0
You can use Task Scheduler for Windows Platform and configure which file to call at Login Time. 

C:\Windows\system32\taskschd is the location.

Create a basic Task or Create Task...... are the options.!!
You can schedule the time of your task to get executed.
Sambhav
  • 208
  • 2
  • 16