Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

java - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...