VB如何运行程序就建立一个本程序的快捷方式!
如果在不同的文件目录运行,快捷方式也要能运行到程序!
另: 还有一个问题!  比如桌面上有连个EXE程序,名称分别为1.EXE和2.EXE 如果直接双击运行2.EXE就提示“非法运行”要双击1.EXE才能正常运行2.EXE这个程序! 请问怎么搞?

解决方案 »

  1.   

    Private Declare Function fCreateShellLink Lib "STKIT432.DLL" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArgs As String) As LongSub Command1_Click()
    Dim lReturn As Long
    '添加到桌面
    lReturn = fCreateShellLink("..\..\Desktop", "Shortcut to Calculator", "c:\windows\calc.exe", "")
    End Sub
      

  2.   

    参考一下我写的(怎样用代码创建桌面快捷方式):http://topic.csdn.net/u/20080328/15/9152a78b-05b4-4c04-810d-15ad59408d33.html
      

  3.   

    Option Explicit
    '*************************************************************************
    '**模 块 名:ModCreateLnk
    '**说    明:创建快捷方式
    '**创 建 人:嗷嗷叫的老马
    '**日    期:2007年6月22日
    '**备    注: 紫水晶工作室 版权所有
    '**          更多模块/类模块请访问我站:  http://www.m5home.com
    '**版    本:V1.0
    '*************************************************************************Public Sub mShellLnk(ByVal LnkName As String, IconFileIconIndex As String, ByVal FilePath As String, Optional ByVal FileName As String, Optional ByVal StrArg As String, Optional ByVal HookKey As String = "", Optional ByVal StrRe As String = "", Optional ByVal strDesktop As String = "")
        Dim WshShell As Object, WScript As Object, oShellLink As Object
        
        Set WshShell = CreateObject("WScript.Shell")
        If strDesktop = "" Then strDesktop = WshShell.SpecialFolders("Desktop")                      '桌面路径
        If UCase(Right(LnkName, 4)) = ".LNK" Then
            Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & LnkName)                   '创建快捷方式,参数为路径和名称
        Else
            Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & LnkName & ".lnk")
        End If
        oShellLink.TargetPath = FilePath & "\" & FileName
        oShellLink.Arguments = StrArg
        oShellLink.WindowStyle = 1       '风格
        oShellLink.Hotkey = HookKey       '热键
        oShellLink.IconLocation = IconFileIconIndex       '图标
        oShellLink.Description = StrRe       '快捷方式备注内容
        oShellLink.WorkingDirectory = FilePath       '源文件所在目录
        oShellLink.Save         '保存创建的快捷方式
        Set WshShell = Nothing
        Set oShellLink = Nothing
    End Sub