Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Desktop shortcut

I am working on a java application.

I want to create desktop shortcut of my application's Exe file.

Is is possible to do it from my application itself ? Or user has to do it manually by right clicking ?

like image 653
geek_guy Avatar asked Dec 26 '22 07:12

geek_guy


1 Answers

package farzi;

import net.jimmc.jshortcut.JShellLink;

public class Sc {
    JShellLink link;
    String filePath;

    public Sc() {
        try {
            link = new JShellLink();
            filePath = JShellLink.getDirectory("")
                + "C:\\Program Files\\Internet Explorer\\iexplore.exe";

        } catch (Exception e) {

        }

    }

    public void createDesktopShortcut() {

        try {
            link.setFolder(JShellLink.getDirectory("desktop"));
            link.setName("ie");
            link.setPath(filePath);
            link.save();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    public static void main(String a[]) {
        Sc sc = new Sc();
        sc.createDesktopShortcut();
    }
}

you can get the jar from here

like image 117
Hussain Akhtar Wahid 'Ghouri' Avatar answered Jan 09 '23 13:01

Hussain Akhtar Wahid 'Ghouri'