First, Java implementation of the. exe program boot automatically
1. Description
The Java project that I wrote in Eclipse was packaged with the Exe4j Wizard as an. exe executable file and enabled the user to boot automatically.
2. Steps
1. Get the path to the. exe executable file in the software
2. On the Windows system, the boot bar holds the shortcut to the. exe executable file, enabling the boot to start automatically.
3. Code
private void Startfoldermethod () {String path = System.getproperty ("User.dir") + "\\appName.exe";//program execution file path, I am directly placed in the project root directory under the string startfolder = ""; Get the operating system name, determine what version of Windows, this can be added as needed, the 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")) { //Get system boot 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); The shortcut holds the address link.setname ("AppName"); Shortcut name, you can arbitrarily take link.setpath (path); The shortcut points to the program address Link.save ();}}
Ii. Java Implementation Desktop shortcuts for creating. exe programs
1. Description
A project has an. exe program that creates a desktop shortcut to the program
2. Steps
1. get the operating system desktop path
2. get the path to the. exe executable file in the software
3. Create a desktop shortcut
private void CreateShortcut () {//Gets the system desktop path of 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); The shortcut holds the address link.setname ("AppName"); Shortcut name Link.setpath (path); The shortcut points to address link.save ();}
Summary: As long as the program starts to invoke the above method, you can implement the Windows system startup and desktop shortcut creation, you can directly click on the desktop shortcut to run the program.
Java implementation software program boot automatically start and create the program's desktop shortcut source code