有谁了解Windows的快捷方式文件(*.lnk)的格式?
如何提取对应的EXE文件路径与icon指向等.希望有实例(重酬)
多谢!多谢!
如何提取对应的EXE文件路径与icon指向等.希望有实例(重酬)
多谢!多谢!
解决方案 »
- 如何把一个COM+打包成一个安装程序,安装后,通过"组件服务"能查看到这个COM+
- msgbox问题
- 麻烦各位帮忙看看这句话啥意思(本人菜鸟)
- 没有边框的窗体能不能用Setwindowlong改变为有无框吗?
- DataGrid控件 与 ADO对象的连接问题?谢谢各位!
- mshflexgrid 控件的列标题
- 有关ADO的问题,急急急!!!(100分)
- 如何在VB程序中控制并实施关闭EXCEL。(用API行不?)急求解决方法。
- vb中多线程的问题
- 问题为了,请教高手,用vb导出MDB数据库的表为文本文件,如下:
- WM_LBUTTONDOWN的值是多少?
- VB开发的个人防火墙软件,测试,来着有分,要源程序的开口
但我想做的是反向操作,想提取一个对应的EXE文件路径………
' 假设要从f:\vb.lnk提取对就在的.exe文件的路径Option ExplicitPrivate Sub Command1_Click()
Dim lnkObj As New cShellLink
Dim ExeFile As String, WorkDir As String, ExeArgs As String
Dim IconFile As String, IconIdx As Long, ShowCmd As Long
lnkObj.GetShellLinkInfo "f:\vb.lnk", ExeFile, WorkDir, ExeArgs, IconFile, IconIdx, ShowCmd
Print "Exefile = ", ExeFile
Print "WorkDir = ", WorkDir
Print "ExeArgs = ", ExeArgs
Print "IconFile = ", IconFile
Print "IconIdx = ", IconIdx
Print "ShowCmd = ", ShowCmd
End Sub
[email protected]
发过去了,也没什么新鲜的,就三个函数。 :)
source code. it has been so long that i can't remember if this was the file
i got working, so someone should test it out (i don't have time). however,
it basically decodes the windows .lnk file format to find out what it is a
shortcut to, and determines if that is a directory (i was going to write a
unix type ln command using .lnk file formats.....). there are 2 files here.
one is a c version, the other is a c++ version.... hope this helps....
-donald murray
============================================
c version
============================================
#include <windows.h>
#include <windowsx.h>
#include <objbase.h>
#include <shlobj.h>
#include <stdio.h>
#include <initguid.h>
#include <string.h>
main(int ac, char *av[])
{
ishelllink *psl;
hresult hres;
win32_find_data wfd;
char szgotpath[max_path];
ipersistfile *ppf;
if (ac != 2)
{
printf("syntax: ln <pathname>\n");
return 0;
}
hres = coinitialize(null);
if (!succeeded(hres))
printf("could not open the com library\n");
hres = cocreateinstance(&clsid_shelllink, null, clsctx_inproc_server,
&iid_ishelllink, (lpvoid *)&psl);
if (succeeded(hres))
{
hres = psl->lpvtbl->queryinterface(psl, &iid_ipersistfile, &ppf);
if (succeeded(hres))
{
word wsz[max_path];
multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path);
hres = ppf->lpvtbl->load(ppf, wsz, stgm_read);
if (succeeded(hres))
{
hres = psl->lpvtbl->resolve(psl, 0, slr_any_match);
if (succeeded(hres))
{
strcpy(szgotpath, av[1]);
hres = psl->lpvtbl->getpath(psl, szgotpath, max_path,
(win32_find_data *)&wfd, slgp_shortpath );
if (!succeeded(hres))
printf("getpath failed!\n");
printf("this points to %s\n", wfd.cfilename);
if (wfd.dwfileattributes & file_attribute_directory)
printf("this is a directory\n");
}
}
else
printf("ipersistfile load error\n");
ppf->lpvtbl->release(ppf);
}
else
printf("queryinterface error\n");
psl->lpvtbl->release(psl);
}
else
printf("cocreateinstance error - hres = %08x\n", hres);
return 0;
}==================================
c++ version
==================================
#include <windowsx.h>
#include <objbase.h>
#include <shlobj.h>
#include <stdio.h>
#include <initguid.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>// this program should print out whether the file is a link and where it
// points to and whether it is a directory or not.
//
main(int ac, char *av[])
{
if (ac != 2)
{
printf("syntax: ln <pathname>\n");
return 0;
}
ishelllink *psl; // pointer to ishelllink i/f
hresult hres;
win32_find_data wfd;
char szgotpath[max_path];
// get pointer to the ishelllink interface.
hres = cocreateinstance(clsid_shelllink, null, clsctx_inproc_server,
iid_ishelllink, (lpvoid *)&psl);
if (succeeded(hres))
{
// get pointer to the ipersistfile interface.
ipersistfile *ppf;
hres = psl->queryinterface(iid_ipersistfile, (lpvoid *)&ppf);
if (succeeded(hres))
{
word wsz[max_path];
// ensure string is unicode.
multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path);
// load the shell link
hres = ppf->load(wsz, stgm_read);
if (succeeded(hres))
{
// resolve the link.
hres = psl->resolve(0, slr_any_match);
// ^
// using 0 instead -| of hwnd, as hwnd is only used if
// interface needs to prompt for more information. should use
// hwnd from current console in the long run.
if (succeeded(hres))
{
strcpy(szgotpath, av[1]);
hres = psl->getpath(szgotpath, max_path,
(win32_find_data *)&wfd, slgp_shortpath );
if (!succeeded(hres))
printf("getpath failed!\n");
printf("this points to %s\n", wfd.cfilename);
if (wfd.dwfileattributes & file_attribute_directory)
printf("this is a directory\n");
}
}
else
printf("ipersistfile load error\n");
ppf->release();
}
else
printf("queryinterface error\n");
psl->release();
}
else
printf("cocreateinstance error - hres = %08x\n", hres);
return 0;
}[email protected]