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

   2023-02-07 学习力0
核心提示:首先说我现在用的一种,最有效的也是最简单的,用dos 、bat批处理和可执行文件完成,在DocManager目录下有DocManager.exe需要生成创建快捷方式,去微软官方下载SHORTCUT.EXE 版本 4.0.950,放在同目录下,然后再同目录下新建bat文件“快捷方式.bat”,内容如
首先说我现在用的一种,最有效的也是最简单的,用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 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 StringByVal 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 LongByVal szApp As StringByVal szOtherStuff As StringByVal hIcon As LongAs Long
27    Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As LongByVal nFolder As Long, pidl As ITEMIDLIST) As Long
28    Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As LongByVal pszPath As StringAs 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 LongAs 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    在Ifvb和dos批处理创建或生成快捷方式Else之间加上:
 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 > 0Then
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    在Ifvb和dos批处理创建或生成快捷方式 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  :::设置快捷方式从哪个文件提取图标


 
反对 0举报 0 评论 0
 

免责声明:本文仅代表作者个人观点,与乐学笔记(本网)无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
    本网站有部分内容均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责,若因作品内容、知识产权、版权和其他问题,请及时提供相关证明等材料并与我们留言联系,本网站将在规定时间内给予删除等相关处理.

  • Windows API Reference for C#, VB.NET
    不错的.net 下用API的参考站点地址在:http://www.webtropy.com/articles/Win32-API-DllImport-art9.asp 下面摘抄分类,便于大家直接就拿来用: File, Memory, Process, Threading, Time, Console, and Comm control(kernel32.dll) _hread_hwrite_lclose_lcr
    03-16
  • 一个基于API的VB.net串口通讯类 vbnet串口通信
    VB.net的串口通讯支持总是让人觉得有所不足,在使用VB6的MsComm32.ocx时,很多人都会在VB.net的开发中觉得很困扰。    这里讲述的VB.net串口通讯类使用native代码,并且它是通API调用实现的,你会发现VB.net的串口通讯就是这么简单。    在说明如何使
    02-12
  • [VB][ASP.NET]FileUpload控件「批次上传 / 多档
    FileUpload控件「批次上传 / 多档案同时上传」的范例 (VB语法) http://www.dotblogs.com.tw/mis2000lab/archive/2008/05/14/3986.aspx    FileUpload控件真的简单好用,不使用它来作批次上传,却要改用别的方法,实在不聪明。要用就一次用到底,公开File
    02-10
  • 第八章 VB中ActiveX控件的使用
    轉自:http://wwww.hyit.edu.cn/edu/vb/study/index.htm第八章          VB中ActiveX控件的使用8.1  概述     这里的ActiveX控件是指VB标准工具箱里没有的控件,用时需从“工程”菜单里选择“部件…”(或右键单击工具箱,从快捷菜单中选择“部
    02-10
  • 第二章 VB的界面设计
    轉自:http://wwww.hyit.edu.cn/edu/vb/study/index.htm第二章         VB的界面设计2.1  VB用户界面设计基础1. 概述   界面的设计有两步:先绘制控件,然后确定控件属性。   绘制控件:在工具箱里单击想画的控件,在窗体里按下鼠标并拖曳,然后
    02-10
  • C#/VB.NET 获取Excel中图片所在的行、列坐标位置
    C#/VB.NET 获取Excel中图片所在的行、列坐标位
    本文以C#和vb.net代码示例展示如何来获取Excel工作表中图片的坐标位置。这里的坐标位置是指图片左上角顶点所在的单元格行和列位置,横坐标即顶点所在的第几列、纵坐标即顶点所在的第几行。下面是获取图片位置的详细方法及步骤。【程序环境】按照如下方法来引
    02-09
  • VB操作XML
    VB操作XML
    XSL(可扩展样式表语言)是对CSS的一种扩展,功能比CSS强大得多。XML链接是在HTML链接的功能之上加以扩展,可以支持更为复杂的链接,通过XML链接,不仅可以在XML文件之间建立链接,还可以建立其他类型数据之间的链接,其规范分为三个部分:XLink语言,XPointe
    02-09
  • VB6多线程,关键段操作 vb6.0 多线程
    Option Explicit Declare Function GetLastError Lib "kernel32" () As Long 'Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long 'Declare Sub ExitThread Lib "kernel32" (Optional ByVal dwExitCode
    02-09
  • VB.NET调用IE,并且等待
                Dim p As New Process            '获得URL            aURL = GetURL()            '获得IE路径            p.StartInfo.FileName = System.Environment.GetFolderPath( _ 
    02-09
  • vb的VSFlexGrid控件 vb msflexgrid
    多行选中VSFlexGrid的SelectionMode = flexSelectionListBox,现在可以配合Ctrl进行多行选择循环取值用vsflexgrid.SelectedRows 可以得到你选择的行的总数量然后用循环可以得到具体的行中具体列的内容Dim Temp  As StringDim i As IntegerFor i =
    02-09
点击排行