怎样在任意目录建立某一可执行文件的快捷方式??

zeric 2000-06-17 08:22:00
我知道的建立快捷方式的方法只有
text1.linktopic
text1.linkmode=2
text1.link........(略)
不过这种方法好像只能在开始菜单的程序目录(或启动目录)里建立,不知道有没有方法能在任意目录里建立(例如用api)
小弟急于要用到这一功能,请各位高手指点指点,小弟万分感谢!!
...全文
130 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yokel 2000-06-18
  • 打赏
  • 举报
回复
生成快捷方式的示例代码可以在VB5或VB6中的安装程序示例中找到,具体目录为:
SetupKit/Setup1/Setup1.vbp
你可以打开此工程文件,可找到有关声明:
Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, ByVal fPrivate As Long, ByVal sParent As String) As Long
以上所说的Dll都是安装盘中的.
CSDN上回答的都是用安装盘中的DLL,
应该有API函数调用,见下:
-----------------------以下再BAS中定义-------------------
Public Const ERROR_SUCCESS As Long = 0
Public Const CSIDL_DESKTOP As Long = &H0
Public Const CSIDL_PROGRAMS As Long = &H2
Public Const CSIDL_STARTMENU As Long = &HB
Public Const CSIDL_DESKTOPDIRECTORY As Long = &H10

Public Const FO_COPY As Long = &H2
Public Const FOF_SILENT As Long = &H4
Public Const FOF_RENAMEONCOLLISION As Long = &H8
Public Const FOF_NOCONFIRMATION As Long = &H10

Public Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type

Public Declare Function SHFileOperation Lib "shell32.dll" _
Alias "SHFileOperationA" _
(lpFileOp As SHFILEOPSTRUCT) As Long

Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" _
(ByVal pidl As Long, _
ByVal pszPath As String) As Long

Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
(ByVal hwndOwner As Long, _
ByVal nFolder As Long, _
pidl As Long) As Long

Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)


Public Sub CreateDesktopLink(sSource As String, sDestination As String)

'working variables
Dim sFiles As String
Dim SHFileOp As SHFILEOPSTRUCT

'terminate passed strings with a null
sSource = sSource & Chr$(0)
sDestination = sDestination & Chr$(0)

'set up the options
With SHFileOp
.wFunc = FO_COPY
.pFrom = sSource
.pTo = sDestination
.fFlags = FOF_SILENT Or FOF_NOCONFIRMATION
End With

'and perform the copy
Call SHFileOperation(SHFileOp)

End Sub


Public Function GetSpecialFolder(hWnd As Long, CSIDL As Long) As String

Dim pidl As Long
Dim pos As Long
Dim sPath As String

'fill the pidl with the specified folder item
If SHGetSpecialFolderLocation(hWnd, CSIDL, pidl) = ERROR_SUCCESS Then

'initialize & get the path
sPath = Space$(260)

If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then

'has a null?
pos = InStr(sPath, Chr$(0))

'strip it
If pos Then

'return folder
GetSpecialFolder = Left$(sPath, pos - 1)

End If

Call CoTaskMemFree(pidl)

End If

End If

End Function
----------------------------以下在主程序中----------------
Dim sDeskPath As String
Dim sStartPath As String
Dim sProgramsLinkPath As String

'path to the current user's Programs folder
sStartPath = GetSpecialFolder(Me.hWnd, CSIDL_PROGRAMS)

'path to the current user's Desktop folder
sDeskPath = GetSpecialFolder(Me.hWnd, CSIDL_DESKTOPDIRECTORY)

'from Programs, path to application link
'and application link name
sProgramsLinkPath = "\MyApp\MyApp.lnk"

'create the desktop link with the values
Call CreateDesktopLink(sStartPath & sProgramsLinkPath, sDeskPath)

----------------------结束--------------------------------------
详情请见:http://expert.csdn.net/Topic/10313.shtm
dannyyu 2000-06-18
  • 打赏
  • 举报
回复
给你一个能在c:\目录生成
c:\\Program Files\\Internet Explorer\\IEXPLORE.EXE c:\\WINDOWS\\README.HTM
起始目录为c:\\Program Files\\Internet Explorer
图标为c:\\WINDOWS\\REGEDIT.EXE的第三个图标的link的code以做参考
#include "stdafx.h"
#include "windows.h"
#include "SHLOBJ.H"

int main()
{
HRESULT hres;
IShellLink * psl;
IPersistFile * ppf;

CoInitialize(NULL);
hres=(HRESULT)CoCreateInstance(CLSID_ShellLink,NULL,CLSCTX_INPROC_SERVER,IID_IShellLink,(void**)&psl) ;
if(FAILED(hres))
{
CoUninitialize();
return -1;
}
psl->SetPath("c:\\Program Files\\Internet Explorer\\IEXPLORE.EXE");
psl->SetArguments("c:\\WINDOWS\\README.HTM");
psl->SetDescription("note");
psl->SetWorkingDirectory("c:\\Program Files\\Internet Explorer");
psl->SetIconLocation("c:\\WINDOWS\\REGEDIT.EXE",2);

hres = (HRESULT)(psl->QueryInterface(IID_IPersistFile,(void**)&ppf)) ;
if(FAILED(hres))
{
CoUninitialize();
return -1;
}
hres = ppf->Save(L"c:\\link.lnk", STGM_READWRITE);
ppf->Release();
psl->Release();

CoUninitialize();
return 0;
}

7,759

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧