java调用vbs生成文件快捷方式

java代码

/**
 *
 * @param creatVbsPath  vbs脚本路径
 * @param oldPath       快捷方式路径
 * @param newPath       文件路径
 * @throws IOException
 */


    public static  void creatVbsPath(String creatVbsPath, String oldPath, String newPath) {
    String content = new String();
    content = "Set WshShell=CreateObject(\"WScript.Shell\") : Set oShellLink=WshShell.CreateShortcut(\"" + oldPath + "\") : oShellLink.TargetPath=\"" + newPath + "\" : oShellLink.WindowStyle=1 : oShellLink.Save\n";
    File file = new File(creatVbsPath);
    /**
     * 如果文件不存在,则创建
     */
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    try{
        FileOutputStream write = new FileOutputStream(creatVbsPath);
        OutputStreamWriter out = new OutputStreamWriter(write);
        out.write(content);
        out.close(); // 最后记得关闭文件
        System.gc();
        String[] cpCmd  = new String[]{"wscript ", creatVbsPath};
        Runtime.getRuntime().exec(cpCmd);
    }catch (Exception e){
        e.printStackTrace();
    }
}

vbs脚本:以.vbs结尾文件

Set WshShell=CreateObject("WScript.Shell") : Set oShellLink=WshShell.CreateShortcut("C:\Users\data-1\Desktop\test\fghfd.lnk") : oShellLink.TargetPath="C:\Users\data-1\Desktop\test1\ttts.txt" : oShellLink.WindowStyle=1 : oShellLink.Save
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值