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.