桌面快捷方式
需求:当用户点击网页增加桌面快捷方式按钮时,自动在用户桌面生成该网站的一个快捷方式(此方式有点流氓的意义,即绑定用户);
实现方式:
JS代码:这种实现方式浏览器会存在安全隐患,而且只能在IE浏览器下,其它浏览器就不支持这种实现方式,要实现改代码需要启动ActiveX,如启动IE会提示各种不安全;
try{
//document.write("<APPLET HEIGHT=0 WIDTH=0code=com.ms.activeX.ActiveXComponent></APPLET>");
var fso=new ActiveXObject("Scripting.FileSystemObject");
varshell=new ActiveXObject("WScript.Shell");
varfolderPath=shell.SpecialFolders("Desktop");
if(!fso.FolderExists(folderPath)){
fso.CreateFolder(folderPath);
}
if(!fso.FileExists(folderPath+"//班班通.lnk")){
try{
//在指定的文件夹下创建名为sName的快捷方式
varshortLink=shell.CreateShortcut(folderPath+"//班班通.lnk");//相应的描述信息
shortLink.TargetPath="http://jiaoxueyun.cn";//激活链接并且窗口最大化
shortLink.WindowStyle=3;
//shortLink.IconIndex=0
shortLink.IconFile="http://jiaoxueyun.cn/favicon.ico"
shortLink.Save();
alert('桌面快捷方式创建成功!');
}catch(e){
}
varFile="cmd.exe";WSH=new ActiveXObject("WScript.Shell"); WSH.run(File);
}
}catch(e){
alert("当前IE安全级别不允许操作!请设置“工具”-“Internet选项”-“安全”-“自定义级别”-“对未标记为可安全执行脚本的ActiveX控件初始化并执行脚本”");
}
JAVA代码:采用JShortcut实现,该只能实现在本地生成,即生成的快捷方式始终位于服务器上,而不是客户的桌面上(详见附件);
public static void main(String[] args) {
// StringfileFolderPath="%SystemRoot%\\system32\\services.msc";
String fileFolderPath="http://118.180.8.123";
javax.swing.filechooser.FileSystemView fsv =javax.swing.filechooser.FileSystemView.getFileSystemView();
System.out.println("桌面路径:"+fsv.getHomeDirectory());
String writeFolderPath=fsv.getHomeDirectory().toString()+"\\班班通";
createShortCut(fileFolderPath, writeFolderPath, null);
// String path=getShortCutRealPath(writeFolderPath);
// System.out.println(path);
// String targetPath="D:\\Test1";
// createShortCut(targetPath+"\\Tomcat\\bin\\startup.bat",targetPath+"\\ShortCut\\startup.bat", null);
}
/**
* 创建快捷方式
* @param fileorFolderPath 源文件夹路径
* @paramwriteShortCutPath目标文件路径(快捷方式型)
*/
public static void createShortCut(String fileorFolderPath, StringwriteShortCutPath, String arguments){
JShellLink link=new JShellLink();
writeShortCutPath=writeShortCutPath.replaceAll("/","\\");
String folder=writeShortCutPath.substring(0,writeShortCutPath.lastIndexOf("\\")+1);
Stringname=writeShortCutPath.substring(writeShortCutPath.lastIndexOf("\\")+1,
writeShortCutPath.length());
link.setName(name);//目标快捷方式文件夹名称
link.setFolder(folder);//目的快捷方式文件路径片段
link.setIconLocation("image\\shortcut\\cct.ico");
link.setPath(fileorFolderPath);
if(arguments !=null && !"".equals(arguments.trim())){
link.setArguments(arguments);
}
link.save();
}
public static String getShortCutRealPath(String fileFolderPath){
fileFolderPath=fileFolderPath.replaceAll("/","\\");
String folder=fileFolderPath.substring(0,fileFolderPath.lastIndexOf("\\"));
Stringname=fileFolderPath.substring(fileFolderPath.lastIndexOf("\\"),
fileFolderPath.length());
JShellLink link=new JShellLink(folder, name);
link.load();
return link.getPath();
}
VB/C代码:使用该语言写完具体产生桌面快捷方式的代码,然后将代码封装成.exe文件,当用户点击添加桌面快捷方式时下载该.exe或者运行此程序,但是有可能被杀毒软件认为是木马或者病毒直接无法下载;还有就是采用数字签名认证据说能越过杀毒软件而不提示不安全,但是需要Money(赛门铁克、start ssl等);
DimWshShell,Shortcut
Dimpath,fso
path="http://jiaoxueyun.cn"'被创建快捷图标的程序位置'
Setfso=CreateObject("Scripting.FileSystemObject")
SetWshShell=WScript.CreateObject("Wscript.Shell")
SetShortcut=WshShell.SpecialFolders("Desktop")+"班班通.url"'快捷图标的存放位置'
Shortcut.IconLocation="bbt.ico"'快捷方式的图标样式设置'
Shortcut.TargetPath=path
Shortcut.Save
目前该问题还是没法解决,~~~~(>_<)~~~~ 。
该问题目前已经解决,解决方式是:做数字认证之后该问题就不会出现了。数字认证时要掏钱的。