使用Java制作桌面快捷方式和开始菜单项!!

neek2000 neek2000 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.io.*;
import javax.swing.*;

public class ShortCut{

public static String osName = System.getProperty("os.name");

public static void main(String[] args){
ShortCut sc = new ShortCut();
File installDir = new File("D:\\install\\");
boolean ok = sc.createWindowsShortcuts(installDir, "install.bat", "install", "winamp");
System.out.println(ok);
}
public boolean createWindowsShortcuts(File installDir, String runnable, String folder, String name){
String command = null;
if(osName.indexOf("9") != -1)
command = "command.com /c cscript.exe /nologo ";
else
command = "cmd.exe /c cscript.exe /nologo ";
if(command != null)
try
{
File shortcutMaker = new File(installDir, "makeshortcut.js");
PrintStream out = new PrintStream(new FileOutputStream(shortcutMaker));
out.println("WScript.Echo(\"Creating shortcuts...\");");
out.println("Shell = new ActiveXObject(\"WScript.Shell\");");
out.println("ProgramsPath = Shell.SpecialFolders(\"Programs\");");
out.println("fso = new ActiveXObject(\"Scripting.FileSystemObject\");");
out.println("if (!fso.folderExists(ProgramsPath + \"\\\\" + folder + "\"))");
out.println("\tfso.CreateFolder(ProgramsPath + \"\\\\" + folder + "\");");
out.println("link = Shell.CreateShortcut(ProgramsPath + \"\\\\" + folder + "\\\\" + name + ".lnk\");");
out.println("link.Arguments = \"\";");
out.println("link.Description = \"" + name + "\";");
out.println("link.HotKey = \"\";");
out.println("link.IconLocation = \"" + escaped(installDir.getAbsolutePath()) + "\\\\" + "winamp.ico,0\";");
out.println("link.TargetPath = \"" + escaped(installDir.getAbsolutePath()) + "\\\\" + runnable + "\";");
out.println("link.WindowStyle = 1;");
out.println("link.WorkingDirectory = \"" + escaped(installDir.getAbsolutePath()) + "\";");
out.println("link.Save();");
out.println("DesktopPath = Shell.SpecialFolders(\"Desktop\");");
out.println("link = Shell.CreateShortcut(DesktopPath + \"\\\\" + name + ".lnk\");");
out.println("link.Arguments = \"\";");
out.println("link.Description = \"" + name + "\";");
out.println("link.HotKey = \"\";");
out.println("link.IconLocation = \"" + escaped(installDir.getAbsolutePath()) + "\\\\" + "winamp.ico,0\";");
out.println("link.TargetPath = \"" + escaped(installDir.getAbsolutePath()) + "\\\\" + runnable + "\";");
out.println("link.WindowStyle = 1;");
out.println("link.WorkingDirectory = \"" + escaped(installDir.getAbsolutePath()) + "\";");
out.println("link.Save();");
out.println("WScript.Echo(\"Shortcuts created.\");");
out.close();
Process p = Runtime.getRuntime().exec(command + " makeshortcut.js", null, installDir);
p.waitFor();
int rv = p.exitValue();
/*try
{
shortcutMaker.delete();
}
catch(Exception exception) { }*/
if(rv == 0)
{
JOptionPane.showMessageDialog(null, "A install test program group has been added to your Start menu\n" + "A install test icon has been added to your desktop.");
return true;
}
else
{
return false;
}
}
catch(Exception e)
{
return false;
}
else
return false;
}
public String escaped(String s)
{
String r = "";
for(int i = 0; i < s.length(); i++)
{
if(s.charAt(i) == '\\')
r = r + '\\';
r = r + s.charAt(i);
}

return r;
}
}
...全文

相关推荐

微服务:从设计到部署.pdf

微服务:从设计到部署.pdf

bjd8246

Java桌面集成组件完整介绍与实践指南

Java Desktop Integration Components(JDIC)是一个为Java桌面应用提供系统集成功能的工具集。它允许Java应用程序与宿主操作系统进行更深层次的交互,实现从简单的系统托盘图标到复杂的文件关联配置,从而提高用户体验和应用的可用性。JDIC为开发者提供了一组丰富的组件和API,使得Java程序能够在Windows、Mac OS X和Linux操作系统上实现更加本地化的功能。这些功能包括但不限于系统托盘图标、文件关联、快捷方式创建等。

焦虑中

微服务从设计到部署.zip

书名:微服务从设计到部署 出版时间:2017年10月 作者:Chris Richardson Floyd Smith 译者:Oopsguy 完整;高清;带目录

shenwenfang

Oracle Essbase & Oracle OLAP: The Guide to Oracle's Multidimensional Solution

Oracle Essbase & Oracle OLAP: The Guide to Oracle's Multidimensional Solution (Osborne ORACLE Press Series) By Michael Schrader, Dan Vlamis, Mike Nader, Chris Claterbos, Dave Collins, Mitch Campbell, Floyd Conrad Publisher: McGraw-Hill Osborne Media 2009-10-07 | 524 Pages | ISBN: 0071621822 | PDF | 11 MB The only book to cover and compare Oracle's online analytic processing products With the acquisition of Hyperion Systems in 2007, Oracle finds itself owning the two most capable OLAP products on the market--Essbase and the OLAP Option to the Oracle Database. Written by the most knowledgeable experts on both Essbase and Oracle OLAP, this Oracle Press guide explains how these products are similar and how they differ. Oracle Essbase & Oracle OLAP will help you architect the Oracle OLAP product that is most appropriate for your application, and build, tune, and maintain OLAP solutions. From the Back Cover Complete Coverage of Oracle Essbase and Oracle OLAP Written by renowned experts on both Oracle Essbase and Oracle OLAP, this exclusive Oracle Press guide explains the unique features and benefits of these powerful online analytic processing products. Oracle Essbase & Oracle OLAP: The Guide to Oracle's Multidimensional Solution provides the details you need to architect the OLAP solution that meets your requirements. Proven techniques for building robust applications and tuning and maintaining your OLAP environment are included in this authoritative resource. Real-world case studies illustrate the material presented. Learn OLAP concepts and history Understand OLAP as a key component of any business intelligence architecture Design and build Oracle OLAP analytic workspaces Plan and create Oracle Essbase databases Generate reports from Oracle OLAP, Oracle Essbase, Oracle Business Intelligence Enterprise Edition, and other tools Accelerate and enhance data warehouses with Oracle OLAP Use Oracle Essbase with performance management applications, including Oracle Hyperion Planning, Oracle Hyperion Profitability and Cost Management, Oracle Crystal Ball, and Oracle Smart Space Develop custom applications using Java APIs Configure, optimize, tune, and maintain Oracle Essbase and Oracle OLAP

oopoopoop

idea2025-free.zip

idea2025-free.zip

qq_45190508
评论 1
收藏 已收藏
分享
返回顶部
neek2000
Java SE 62,620 成员 307,251 内容