vb和dos批处理创建或生成快捷方式

https://www.cnblogs.com/gszhl/archive/2009/04/23/1441753.html

 

vb和dos批处理创建或生成快捷方式

 
首先说我现在用的一种,最有效的也是最简单的,用dos 、bat批处理和可执行文件完成,在DocManager目录下有DocManager.exe需要生成创建快捷方式,去微软官方下载SHORTCUT.EXE 版本 4.0.950,放在同目录下,然后再同目录下新建bat文件“快捷方式.bat”,内容如下: Shortcut.exe /f /t "%cd%\DocManager.exe" /n "%USERPROFILE%\桌面\DocManager.lnk" /d "%cd%"
双击 快捷方式.bat,你会看到你的愿望实现了,在桌面看见了一个快捷方式,图标与原来可执行程序的图标相同。你也可以在VB或者VC里面调用这个bat文件,达到你的目的。
有自带的帮助的
Shortcut [Version 1.11]
Creates, modifies or queries Windows shell links (shortcuts)
The syntax of this command is:
Shortcut.exe /F:filename /A:C|E|Q [/T:target] [/P:parameters] [/W:workingdir]       [/R:runstyle] [/I:icon,index] [/H:hotkey] [/D:description]
/F:filename : Specifies the .LNK shortcut file. /A:action    : Defines the action to take (C=Create, E=Edit or Q=Query). /T:target    : Defines the target path and file name the shortcut points to. /P:parameters   : Defines the command-line parameters to pass to the target. /W:working dir : Defines the working directory the target starts with. /R:run style : Defines the window state (1=Normal, 3=Max, 7=Min). /I:icon,index   : Defines the icon and optional index (file.exe or file.exe,0). /H:hotkey    : Defines the hotkey, a numeric value of the keyboard shortcut. /D:description : Defines the description (or comment) for the shortcut.
Notes: - Any argument that contains spaces must be enclosed in "double quotes". - If Query is specified (/A:Q), all arguments except /F: are ignored. - To find the numeric hotkey value, use Explorer to set a hotkey and then /A:Q - To prevent an environment variable from being expanded until the shortcut is launched, use the ^ carat escape character like this: ^%WINDIR^%
Examples: /f:"%ALLUSERSPROFILE%\Start Menu\Programs\My App.lnk" /a:q /f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:c /t:^%WINDIR^%\Notepad.exe /h:846 /f:"%USERPROFILE%\Desktop\Notepad.lnk" /a:e /p:C:\Setup.log /r:3
An argument of /? or -? displays this syntax and returns 1. A successful completion will return 0.
VB生成快捷方式有很多
我总结一下大致共3种

第一种,也最简单的最实用的一种,现在在还很少看见人使用,就是直接调用Wscript.Shell

dim objshell Set objshell = CreateObject("Wscript.Shell")

Set objShellLink = objshell.CreateShortcut(要存放的位置 & "SVCH0ST.lnk") objShellLink.TargetPath = App.Path + "\" + App.EXEName + ".exe" objShellLink.Save

以上说的不清楚,下面是一个详细的介绍:

复制代码
 1 '创建快捷方式  2 '引用windows scripting host object model  3      4   Dim WSH As WshShell  5   Dim Urllink As WshShortcut  6   Dim DeskPath As String  7     8   Set WSH =New WshShell  9   DeskPath = WSH.SpecialFolders("Desktop"'获得桌面路径 10   '可以用wsh_shell.expandenvironmentstrings("%windir%")获得windows路径 11   Set Urllink = WSH.CreateShortcut(DeskPath & "\Test.lnk") 12   With Urllink 13   .TargetPath = "d:\test.txt" '目标 14   .IconLocation = WSH.ExpandEnvironmentStrings _ 15   ("%SystemRoot%\system32\SHELL32.dll,70"'图标 16   .Hotkey = "ctrl+shift+F" '快捷键 17   .WorkingDirectory = "d:\" '起始位置 18   .WindowStyle = 1 '运行方式 19   '1 激活并显示窗口。如果该窗口被最小化或最大化,则系统将其还原到初始大小和位置。 20   '3 激活窗口并将其显示为最大化窗口? 21   '7 最小化窗口并激活下一个顶级窗口? 22   '可以设的值有wshhide?wshmaximizedfocus?wshminimizedfocus? 23   'wshminimizednofocus?wshnormalfocus?wshnormalnofocus 24   End With 25   Urllink.Save '保存快捷方式 26  27 '打开链接 28 Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _ 29   ByVal hwnd As Long, _ 30   ByVal lpOperation As String, _ 31   ByVal lpFile As String, _ 32   ByVal lpParameters As String, _ 33   ByVal lpDirectory As String, _ 34   ByVal nShowCmd As Long _ 35 As Long 36  37 

转载于:https://www.cnblogs.com/ifreesoft/p/8422358.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值