Java implementation software program boot automatically start and create the program's desktop shortcut source code

Source: Internet
Author: User

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

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.