中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-29 22:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 网上看到的用批处理建立lnk快捷方式 查看 1,135 回复 6
楼 主 网上看到的用批处理建立lnk快捷方式 发表于 2010-06-15 09:58 ·  中国 广东 梅州 电信
中级用户
★★
积分 262
发帖 129
注册 2007-07-11 06:50
18年会员
UID 93679
性别 男
状态 离线

Sub bat
echo create_shortcut
start wscript -e:vbs "%~f0"
Exit Sub
End Sub

Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Dim WshShell,pa
Set WshShell = WScript.CreateObject("WScript.Shell")
Pa = WshShell.CurrentDirectory
set oShellLink = WshShell.CreateShortcut(strDesktop & "\火炬之光.lnk")
oShellLink.TargetPath = pa & "\开始游戏.exe"
oShellLink.WindowStyle = 2
oShellLink.IconLocation = pa & "\开始游戏.exe, 0"
oShellLink.WorkingDirectory = pa
oShellLink.Save


真的很强大.我搞不懂SUB本来就不是可以运行的命令,可是少了它却不行了!
2 发表于 2010-06-15 11:43 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
积分 1,039
发帖 897
注册 2009-03-01 15:34
17年会员
UID 140302
性别 男
来自 在地狱中仰望天堂
状态 离线
批处理时:
Sub bat,批处理中因为不存在Sub,输出错误显示并跳过,在vbs中定义sub过程的name为bat
start wscript -e:vbs "%~f0",把整个批处理重新按vbs运行
Exit Sub,在vbs中从sub 过程中退出,在批处理中,只使用Exit,退出批处理
批处理也可以写成:
more +3<%~fs0>$.vbs
cscript //nologo $.vbs&del $.vbs
Exit
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Dim WshShell,pa
Set WshShell = WScript.CreateObject("WScript.Shell")
Pa = WshShell.CurrentDirectory
set oShellLink = WshShell.CreateShortcut(strDesktop & "\火炬之光.lnk")
oShellLink.TargetPath = pa & "\开始游戏.exe"
oShellLink.WindowStyle = 2
oShellLink.IconLocation = pa & "\开始游戏.exe, 0"
oShellLink.WorkingDirectory = pa
oShellLink.Save
vbs:
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Dim WshShell,pa
Set WshShell = WScript.CreateObject("WScript.Shell")
Pa = WshShell.CurrentDirectory
set oShellLink = WshShell.CreateShortcut(strDesktop & "\火炬之光.lnk")
oShellLink.TargetPath = pa & "\开始游戏.exe"
oShellLink.WindowStyle = 2
oShellLink.IconLocation = pa & "\开始游戏.exe, 0"
oShellLink.WorkingDirectory = pa
oShellLink.Save


[ Last edited by Hanyeguxing on 2010-6-15 at 12:01 ]
3 发表于 2010-06-15 18:30 ·  中国 广东 梅州 电信
中级用户
★★
积分 262
发帖 129
注册 2007-07-11 06:50
18年会员
UID 93679
性别 男
状态 离线
这样用BAT建立快捷方式比建立*.url就好得多了。

也用不着ECHO来输出VBS来建立快捷方式了。

以前我以为没办法直接调用VBS来建立快捷方式,因为换行的代码太多了。
4 Re 3 楼 发表于 2010-06-15 20:03 ·  中国 重庆 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
也可以在BAT里面调用mshat来创建.lnk,不一定要生成临时的VBS。
.url就更简单了,echo几下就行了,更用不着VBS。
5 发表于 2010-06-15 21:56 ·  中国 广东 梅州 电信
中级用户
★★
积分 262
发帖 129
注册 2007-07-11 06:50
18年会员
UID 93679
性别 男
状态 离线
url本来是个网址的形式的,根本不具有lnk快捷方式所具有的性质.所以要建立桌面图标尽量还是要lnk的好.

我想知道怎么调用mshat来建立lnk呢?能举个例子吗?
6 发表于 2010-06-16 12:20 ·  中国 山东 联通
新手上路
积分 3
发帖 3
注册 2009-10-02 12:29
16年会员
UID 152535
性别 男
状态 离线
@echo off
set str=%*
call set str=%%str:%1=%%
mshta.exe VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\%~n1.lnk""):b.TargetPath=""%~1"":b.Arguments=""%str%"":b.WorkingDirectory=""%~dp1"":b.Save:close")

::Arguments 目标程序参数
::Description 快捷方式备注
::FullName 返回快捷方式完整路径
::Hotkey 快捷方式快捷键
::IconLocation 快捷方式图标,不设则使用默认图标
::TargetPath 目标
::WindowStyle 窗口启动状态
::WorkingDirectory 起始位置
7 发表于 2010-06-16 13:28 ·  中国 吉林 延边朝鲜族自治州 延吉市 电信
银牌会员
★★★
正在学习中的菜鸟...
积分 1,039
发帖 897
注册 2009-03-01 15:34
17年会员
UID 140302
性别 男
来自 在地狱中仰望天堂
状态 离线
Originally posted by kidzgy at 2010-6-15 21:56:
url本来是个网址的形式的,根本不具有lnk快捷方式所具有的性质.所以要建立桌面图标尽量还是要lnk的好.

我想知道怎么调用mshat来建立lnk呢?能举个例子吗?

url和和lnk本身不同,所以不存在谁比谁好的问题
论坛跳转: