I am developing a Java program that needs to run when user turns on his PC, I was suggested to :

create a .bat file

@javaw -jar path/to/jar/Name.jar arguments

drop this in the Windows startup directory

My question is :

  1. Can my Java program save the above file into the Windows startup directory ?
  2. Where is this Windows startup directory on the C: or D: drive ?
  3. How can my Java app find out the location ?
  4. Is it the same on all versions of Windows ?
link|improve this question

80% accept rate
Unsure why this has been closed. Perhaps it should be migrated to Stack OVerflow? – quickly_now Dec 30 '10 at 22:49
feedback

closed as off topic by John T, studiohack, Diago Dec 30 '10 at 22:40

Questions on Super User are expected to generally relate to computer software or computer hardware, within the scope defined in the faq.

3 Answers

This depends on your version of Windows.

In XP the usual location is:

%userprofile%\Start Menu\Programs\Startup

and in 7:

%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Whether your application can save there depends on the permissions of the user running the program.

link|improve this answer
How about other windows versions besides XP and 7 ? – Frank Dec 30 '10 at 21:17
you're targeting windows ME and 98SE????? – aking1012 Dec 30 '10 at 21:23
Instead of having us guess, how about you go ahead and tell us what version you are targeting? – th3dude Dec 30 '10 at 21:24
All windows users, I don't care which version, as long as it's Windows. I hope to use a Java command to find out where it is, any sample code ? – Frank Dec 30 '10 at 22:21
Having a program start automatically is much more difficult on Vista and Win7. Hint: startup programs won't do much for you, nor will registry keys. You need to use the task scheduler. Do some searching on MSDN. – quickly_now Dec 30 '10 at 22:48
feedback

You can create that bat file and place a shortcut to it in (Windows XP):

YourDrive:\Documents and Settings\%userprofile%\Start Menu\Programs\Startup

You can also through it in the All Users startup folder.

The directory is in an entirely different location in Vista/7:

YourDrive:\Users\%username%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
link|improve this answer
How about other windows versions besides XP and 7 ? – Frank Dec 30 '10 at 21:17
Instead of having us guess, how about you just go ahead and tell us what version you are targeting? – th3dude Dec 30 '10 at 21:24
feedback

Guessing you want vista too. Well it's the same as Windows7.

YourDrive:\Users\%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Win95/98/4.0 is basically obsolete. Why do you care?

link|improve this answer
Thanks. Is there any command to execute to get this path ? – Frank Dec 30 '10 at 22:44
feedback

Not the answer you're looking for? Browse other questions tagged or ask your own question.