📄 lnk.htm
字号:
<html>
<head>
<title>file:///e:/kaifa/format/windows/lnk.txt</title>
</head>
<body background="../jpg/di1.JPG">
<p align="center"><font size="6" color="#0000ff">.lnk file format</font></p>
<div align="center"><center>
<table border="0" width="88%">
<tr>
<td width="100%"><pre>it's been a while since i've messed with that, but i dug up the following
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....</pre>
<pre> -donald murray</pre>
<pre>============================================
c version
============================================</pre>
<pre>#include <windows.h>
#include <windowsx.h>
#include <objbase.h>
#include <shlobj.h>
#include <stdio.h>
#include <initguid.h>
#include <string.h></pre>
<pre>main(int ac, char *av[])
{
ishelllink *psl;
hresult hres;
win32_find_data wfd;
char szgotpath[max_path];
ipersistfile *ppf;</pre>
<pre> if (ac != 2)
{
printf("syntax: ln <pathname>\n");
return 0;
}</pre>
<pre> hres = coinitialize(null);
if (!succeeded(hres))
printf("could not open the com library\n");</pre>
<pre> hres = cocreateinstance(&clsid_shelllink, null, clsctx_inproc_server,
&iid_ishelllink, (lpvoid *)&psl);
if (succeeded(hres))
{
hres = psl->lpvtbl->queryinterface(psl, &iid_ipersistfile, &ppf);</pre>
<pre> if (succeeded(hres))
{
word wsz[max_path];</pre>
<pre> multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path);</pre>
<pre> hres = ppf->lpvtbl->load(ppf, wsz, stgm_read);
if (succeeded(hres))
{
hres = psl->lpvtbl->resolve(psl, 0, slr_any_match);</pre>
<pre> if (succeeded(hres))
{
strcpy(szgotpath, av[1]);</pre>
<pre> hres = psl->lpvtbl->getpath(psl, szgotpath, max_path,
(win32_find_data *)&wfd, slgp_shortpath );
if (!succeeded(hres))
printf("getpath failed!\n");</pre>
<pre> 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;
}
</pre>
<pre>==================================
c++ version
==================================</pre>
<pre>#include <windowsx.h>
#include <objbase.h>
#include <shlobj.h>
#include <stdio.h>
#include <initguid.h>
#include <stdlib.h>
#include <io.h>
#include <string.h>
</pre>
<pre>// this program should print out whether the file is a link and where it
// points to and whether it is a directory or not.
//</pre>
<pre>main(int ac, char *av[])
{
if (ac != 2)
{
printf("syntax: ln <pathname>\n");
return 0;
}</pre>
<pre> ishelllink *psl; // pointer to ishelllink i/f
hresult hres;
win32_find_data wfd;
char szgotpath[max_path];</pre>
<pre> // get pointer to the ishelllink interface.</pre>
<pre> hres = cocreateinstance(clsid_shelllink, null, clsctx_inproc_server,
iid_ishelllink, (lpvoid *)&psl);</pre>
<pre> if (succeeded(hres))
{
// get pointer to the ipersistfile interface.</pre>
<pre> ipersistfile *ppf;
hres = psl->queryinterface(iid_ipersistfile, (lpvoid *)&ppf);</pre>
<pre> if (succeeded(hres))
{
word wsz[max_path];</pre>
<pre> // ensure string is unicode.
multibytetowidechar(cp_acp, 0, av[1], -1, wsz, max_path);</pre>
<pre> // load the shell link
hres = ppf->load(wsz, stgm_read);
if (succeeded(hres))
{
// resolve the link.</pre>
<pre> 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.</pre>
<pre> if (succeeded(hres))
{
strcpy(szgotpath, av[1]);</pre>
<pre> hres = psl->getpath(szgotpath, max_path,
(win32_find_data *)&wfd, slgp_shortpath );
if (!succeeded(hres))
printf("getpath failed!\n");</pre>
<pre> 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;
}
</pre>
</td>
</tr>
</table>
</center></div>
<p align="center"><a href="../index.htm">返回</a></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -