Java implements the desktop shortcut source code for Automatic startup and creation of software programs at startup.

Source: Internet
Author: User

Java implements the desktop shortcut source code for Automatic startup and creation of software programs at startup.

One click javareal.exe automatically starts when the program is started.

1. Description

In the java project compiled by eclipse, use exe4j wizardto package an. EXE executable file and enable the user to start automatically at startup.



2. Steps

1. The path of the. exe executable file in the current software.

2. Save the shortcut of the .exe executable file in the startup column of Windows system to enable automatic startup upon startup.


3. Code


Private void startFolderMethod () {String path = System. getProperty ("user. dir ") +" \ appName.exe "; // path of the program execution file, which is String startFolder =" "in the root directory of the Project. // obtain the operating system name, determine the version of windows, which can be added as needed. This method can also determine whether it is another operating System String osName = System. getProperty ("OS. name "); if (osName. equals ("Windows 7") | osName. equals ("Windows 8") {// obtain the System startup directory startFolder = System. getProperty ("user. home ") +" \ AppData \ Roaming \ Microsoft \ Windows \ Start Menu \ Programs \ Startup ";} if (osName. endsWith ("Windows XP") {startFolder = System. getProperty ("user. home ") +" \ "start" Menu \ Program \ Start ";} if (! StartFolder. equals ("") {JShellLink link = new JShellLink (); link. setFolder (startFolder); // saved link in a shortcut. setName ("appName"); // shortcut name, which can be any link. setPath (path); // shortcut pointing to the program address link. save ();}}



Ii. Java now creates the desktop shortcut for the .exe Program

1. Description

A project contains an .exe program, which creates a desktop shortcut for this program.

2. Steps

1. Obtain the desktop path of the Operating System

2. The path of the. exe executable file in the current software.

3. Create a desktop shortcut


Private void createShortcut () {// obtain the system desktop path String desktop = FileSystemView. getFileSystemView (). getHomeDirectory (). getAbsolutePath (); // program execution file path String path = System. getProperty ("user. dir ") +" \ appName.exe "; JShellLink link = new JShellLink (); link. setFolder (desktop); // saved Address link. setName ("appName"); // shortcut name link. setPath (path); // The shortcut points to the address link. save ();}



Summary: as long as the above method is called at the startup of the program, you can start the program on windows and create a desktop shortcut. Then you can click the desktop shortcut to run the program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.