Create Desktop shortcut

前端 未结 3 1741
庸人自扰
庸人自扰 2020-12-21 01:26

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

3条回答
  •  隐瞒了意图╮
    2020-12-21 02:05

    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

提交回复
热议问题