vb和dos批处理创建或生成快捷方式
https://www.cnblogs.com/gszhl/archive/2009/04/23/1441753.html
双击 快捷方式.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 ShellExecute 0, "open","http://community.csdn.net/", _ 38 vbNullString, vbNullString, SW_SHOWNORMAL 39
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
第二种,只要借助于Windows Script Host,建立快捷方式简直就是轻而易举。但首先要引用WSH,选VB的菜单Project->Reference,加入Windows Script Host Model。
ShortCut.BAS文件如下 1 Attribute VB_Name = "ShortCut" 2 Option Explicit 3 4 Public Sub CreateShortCutOnDeskTop(ByVal Name As String, ByVal Description As String) 5 6 Dim x As New IWshRuntimeLibrary.IWshShell_Class 7 Dim y As IWshRuntimeLibrary.IWshShortcut_Class 8 Set y = x.CreateShortcut(x.SpecialFolders.Item("AllUsersDesktop") & "\" & Name & ".lnk") 9 y.TargetPath = App.Path & "\" & App.EXEName 10 y.Description = Description 11 y.WorkingDirectory = App.Path 12 y.Save 13 14
1 Attribute VB_Name = "ShortCut" 2 Option Explicit 3 4 Public Sub CreateShortCutOnDeskTop(ByVal Name As String, ByVal Description As String) 5 6 Dim x As New IWshRuntimeLibrary.IWshShell_Class 7 Dim y As IWshRuntimeLibrary.IWshShortcut_Class 8 Set y = x.CreateShortcut(x.SpecialFolders.Item("AllUsersDesktop") & "\" & Name & ".lnk") 9 y.TargetPath = App.Path & "\" & App.EXEName 10 y.Description = Description 11 y.WorkingDirectory = App.Path 12 y.Save 13 14 End Sub
SpecialFolders是IWshShell_Class类的一个属性,包含了很多特殊目录路径,比如上面的程序就用了AllUsersDesktop,还可以是开始菜单AllUsersStartMenu 等。可以参考MSDN。 CreateShortcut是IWshShell_Class类的一个方法,用于建立快捷方式,其参数是快捷方式的文件名。
然后给出快捷方式的各个属性,最后保存。
第三种
VB展开与打包向导生成的安装程序的工作步骤是这样的: 先运行Setup.exe,这个程序将VB的运行库安装到用户的机器上,然后再调用Setup1.exe。Setup1.exe是由VB写的(正是这个原因所以要先安装VB的运行库),其源程序可以在VB98\Wizards\PDWizard\Setup1中找到。所以如果你对VB的安装程序不满,就可以直接修改Setup1.vbp。对于你的问题,在VB中可以打开Setup1.vbp,然后修改Setup1.frm的Form_Load事件,在其中可以找到如下几行: ' Create program icons (or links, i.e. shortcuts). If (fMainGroupWasCreated = True) Or ((cIcons > 0) And TreatAsWin95()) Then ShowStaticMessageDialog ResolveResString(resPROGMAN) CreateIcons gsICONGROUP ' ' Do the same for other sections in SETUP.LST if you've added your own. ' 'CreateIcons "MySection" 'CreateIcons "MyOtherSection" End If 在If.. End If中加上: OSfCreateShellLink "..\..\Desktop", _ "我的程序", gstrDIR_DEST + "MyProg.exe", "", True, "$(Programs)" 重新编译Setup1.vbp,用Setup1.exe替换原来的Setup1.exe即可。 --------------------------------------------------------------- http://www.cnskye.com/down/show.asp?id=211&page=1 SetupBuilder1.50 中文版用这个吧..先用VB自带的安装程序制作工具找到程序所用的所有Dll和Ocx再用SetupBuilder加工一下..比VB做的安装界面强得多..功能也非常强大
系统文件夹fso.GetSpecialFolder(SystemFolder) , fso.GetSpecialFolder(1) 0 1 2
1 'Form1上添加Timer控件,工程中引用Microsoft Scripting Runtime,将代码复制到窗体代码中: 2 Option Explicit 3 Dim fso As FileSystemObject 4 Dim fd As Folder 5 6 Private Sub Form_Load() 7 Set fso = New FileSystemObject 8 Set fd = fso.GetSpecialFolder(SystemFolder) 9 Timer1.Interval = 60 10 End Sub 11 12 Private Sub Timer1_Timer() 13 If fd.Drive.AvailableSpace <= 500000000 Then 14 '空间小于500MB报警: 15 Beep 16 End If 17 End Sub 18
如何得到“桌面”、“程序”、“收藏夹” "开始"的目录?
1 Const CSIDL_DESKTOP = &H0 2 Const CSIDL_PROGRAMS = &H2 3 Const CSIDL_CONTROLS = &H3 4 Const CSIDL_PRINTERS = &H4 5 Const CSIDL_PERSONAL = &H5 6 Const CSIDL_FAVORITES = &H6 7 Const CSIDL_STARTUP = &H7 8 Const CSIDL_RECENT = &H8 9 Const CSIDL_SENDTO = &H9 10 Const CSIDL_BITBUCKET = &HA 11 Const CSIDL_STARTMENU = &HB 12 Const CSIDL_DESKTOPDIRECTORY = &H10 13 Const CSIDL_DRIVES = &H11 14 Const CSIDL_NETWORK = &H12 15 Const CSIDL_NETHOOD = &H13 16 Const CSIDL_FONTS = &H14 17 Const CSIDL_TEMPLATES = &H15 18 Const MAX_PATH = 260 19 Private Type SHITEMID 20 cb As Long 21 abID As Byte 22 End Type 23 Private Type ITEMIDLIST 24 mkid As SHITEMID 25 End Type 26 Private Declare Function ShellAbout Lib "shell32.dll" Alias "ShellAboutA" (ByVal hWnd As Long, ByVal szApp As String, ByVal szOtherStuff As String, ByVal hIcon As Long) As Long 27 Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long 28 Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long 29 Private Sub Form_Load() 30 'KPD-Team 1998 31 'URL: http://www.allapi.net/ 32 'E-Mail: KPDTeam@Allapi.net 33 'Show an about window 34 ShellAbout Me.hWnd, App.Title, "Created by the KPD-Team 1999", ByVal 0& 35 'Set the graphical mode to persistent 36 Me.AutoRedraw = True 37 'Print the folders to the form 38 Me.Print "Start menu folder: " + GetSpecialfolder(CSIDL_STARTMENU) 39 Me.Print "Favorites folder: " + GetSpecialfolder(CSIDL_FAVORITES) 40 Me.Print "Programs folder: " + GetSpecialfolder(CSIDL_PROGRAMS) 41 Me.Print "Desktop folder: " + GetSpecialfolder(CSIDL_DESKTOP) 42 End Sub 43 Private Function GetSpecialfolder(CSIDL As Long) As String 44 Dim r As Long 45 Dim IDL As ITEMIDLIST 46 'Get the special folder 47 r = SHGetSpecialFolderLocation(100, CSIDL, IDL) 48 If r = NOERROR Then 49 'Create a buffer 50 Path$ = Space$(512) 51 'Get the path from the IDList 52 r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$) 53 'Remove the unnecessary chr$(0)'s 54 GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1) 55 Exit Function 56 End If 57 GetSpecialfolder = "" 58 End Function
发个vb内置的setup1(在VB98\Wizards\PDWizard\Setup1\setup1.vbp目录下)
二、打开名称为 basSetup1 的标准模块,声明两个公用变量: Public lnkName As String Public lnkPath As String
三、在上面打开的 basSetup1 标准模块中找到“CreateShellLink”过程,并找到下面的的内容:
1 If fSuccess Then 2 If fLog Then 3 CommitAction 4 End If 5 Else 6 在IfElse之间加上: 7 If InStr(strLinkPath, ".EXE") Or InStr(strLinkPath, ".exe") Then 8 If lnkName = "" Then 9 lnkName = strLinkName 10 lnkpath = strLinkPath 11 End If 12 End If四、打开名称为frmSetup1的代码窗口,并在Form_Load 事件中找到以下内容: 13 ' 14 ' Create program icons (or links, i.e. shortcuts). 15 ' 16 If fMainGroupWasCreated Or (cIcons > 0) Then 17 ShowStaticMessageDialog ResolveResString(resPROGMAN) 18 CreateIcons gsICONGROUP 19 ' 20 ' Do the same for other sections in SETUP.LST if you've added your own. 21 ' 22 'CreateIcons "MySection" 23 'CreateIcons "MyOtherSection" 24 ' 25 End If 26 在If End If中加上: 27 (VB 5.0中) 28 If MsgBox("是否要创建桌面上快捷方式?", 32 + 4, "创建桌面快捷方式") = vbYes Then 29 OSfCreateShellLink "..\..\Desktop", lnkName, lnkPath, "" 30 End If (VB 6.0中) 31 If MsgBox("是否要创建桌面快捷方式?", 32 + 4, "创建桌面快捷方式") = vbYes Then 32 OSfCreateShellLink "..\..\Desktop", lnkName
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
bat文件的方法:
1 set path=C:\Program Files\TypeEasy2006\TypeEasy.exe :::这里设置要创建快捷方式的程序的完整路径 2 echo [InternetShortcut] >>金山打字.url :::写入快捷方式 3 echo URL="%path%" >>金山打字.url :::把程序路径写入快捷方式 4 echo IconIndex=0 >>金山打字.url :::设置快捷方式用的图标,0开始 5 echo IconFile=C:\Program Files\TypeEasy2006\TypeEasy.exe >>金山打字.url :::设置快捷方式从哪个文件提取图标
vb和dos批处理创建或生成快捷方式的更多相关文章
- windows命令行(DOS批处理)添加任务计划
自动创建每周运行一次的计划任务 创建计划任务可用at,schtasks命令,schtasks提供了很多参数 命令schtasks SCHTASKS /Create [/S system [/U use ...
- 用DOS批处理实现FTP自动上传、下载、清理文件
用DOS批处理实现FTP自动上传.下载.清理文件 最近好像特别的忙,好久没来写点东西了,今天写了一个利用批处理程序完成FTP自动上传.下载.清理文件的程序.赶紧 记录下来,以备日后之用.功能介绍:自动 ...
- DOS批处理延时技术
DOS批处理延时技术 举个例子,我们要延时5秒打开gdh.txt这个文件,可以用以下几个方法 方法一:ping 缺点:时间精度为1秒,不够精确 www.2cto.com @echo off ...
- cocos2d-x教程3:用php或DOS批处理命令来转换文件和解压缩zip
在cocos2d-x使用中,须要不停的转换文件和压缩或解压文件.假设全人工来做,太麻烦了,且easy出错. 我如今把一些用的到批处理贴出来,供大家使用 自己主动把dat文件按数字排序重命名gz.DOS ...
- Ubuntu创建启动器(快捷方式)的方式
解压.tar.gz的navicat之后发现不能自动生成启动器了,研究了一下发现: 虽然不少带有图形界面的程序会在安装时自动在桌面上创建快捷方式,还有一些图形界面程序或者命令行程序可能需要你手动创建快捷 ...
- 利用DOS批处理实现定时关机操作
10月1放假回来,寝室晚上10:30就停电了,最无法让人理解的是第二天早上8:00才来电.原来晚上电脑都是不关机的,开着WiFi一直到天亮,可是现在不行了,电脑如果一直开着第二天早上起来电脑肯定没电, ...
- DOS批处理中%cd%和%~dp0的区别
DOS批处理中%cd%和%~dp0的区别 在DOS的批处理中,有时候需要知道当前的路径. 在DOS中,有两个环境变量可以跟当前路径有关,一个是%cd%, 一个是%~dp0. 这两个变量 ...
- DOS批处理不支持将UNC 路径作为当前目录的巧妙解决方案
DOS批处理不支持将UNC 路径作为当前目录的巧妙解决方案在有些时候,需要在批处理中操作UNC目录,但批处理并不能直接对UNC目录进行操作,怎么办? 废话少说,直接上代码,打开网上邻居→整个网络→Mi ...
- ubuntu系统下创建软件桌面快捷方式
转自ubuntu系统下创建软件桌面快捷方式 默认情况下,ubuntu会将自动安装的软件快捷方式保存在/usr/share/applications目录下,如果我们要创建桌面快捷方式,只需要右键-复制- ...
随机推荐
- nginx流量全copy记录
参考:http://tyrion.iteye.com/blog/2311987 准备两台服务器: 0.0.0.1 0.0.0.2 在 0.0.0.1上 . 下载 wget https://github ...
- 使用Properties读写属性文件
import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; /*Prop ...
- RGB(16进制)_转_TColor
ZC:内存中 COLORREF就是一个DWORD(从定义"COLORREF = DWORD;"就可以看出来),但是 具体的byte R/G/B 的位置是怎么方式的? ZC:Wind ...
- Memcache 笔记(2)
一.Memcache概述出现的原因:随着数据量的增大,访问的集中,使得数据库服务器的负担加重,数据库响应恶化,网站显示延迟等 memcache:是高性能的分布式内存缓存服务器.通过缓存数据库的查询结果 ...
- python中的变量与对象
一. 什么是变量 变量就是以前学习的数学中常见的等式x = 3(x是变量,3是变量值),在编程中,变量不仅可以是数学,还可以是任意数据类型 二. 变量的命名规则 变量名必须是英文大小写.数字和_的组合 ...
- eclispe中使用 maven build启动maven项目和打包项目
1.右键项目2.点击run as按钮 3.点击run configurations 4.配置如下: =============================加油加油加油加油加油加油========= ...
- MongoDB3.0 创建用户
use mydb db.createUser( { "user" : "sa", "pwd": "sa", " ...
- CodeForces-831A-Unimodal Array (水题)
题目链接 /* Name: Copyright: Author: Date: 2018/5/6 19:34:23 Description: */ #include <iostream> # ...
- 2018年 7月总结&8月计划
7月悄然而过... 英语: a打卡率:1号上课没有完成听力,7号上课没有完成阅读,21,22号考试 没有阅读 PS:学习效果测评 1)不要再阅读china English 2)单词要拼写 3)听力句子 ...
- 利用HTML5开发Android笔记(中篇)
资源来自于www.mhtml5.com 杨丰盛老师成都场的PPT分享 一个很简明的demo 可以作为入门基础 学习的过程中做了点笔记 整理如下 虽然内容比较简单 但是数量还是比较多的 所以分了3篇 ( ...