Enumerates the desktop application LNK paths and obtains the corresponding program's absolute path (using the Shgetdesktopfolder function enumeration, and then using COM to query the Ishellfolder,ishelllink and IPersistFile interfaces)

Source: Internet
Author: User

[CPP]View PlainCopy
  1. Enumerate the LNK paths of applications on the desktop
  2. void Enumdesktoplnkpath ()
  3. {
  4. WCHAR Szpath[max_path] = {0};
  5. SHGETSPECIALFOLDERPATHW (NULL, szpath, csidl_desktopdirectory, 0);
  6. ishellfolder* Pshell = NULL;
  7. if (FAILED (Shgetdesktopfolder (&pshell)))
  8. {
  9. return;
  10. }
  11. ishellfolder* pfolder = NULL;
  12. itemidlist* pitem = NULL;
  13. if (FAILED (pshell->parsedisplayname (null, NULL, szpath, NULL, &pitem, NULL) ))
  14. {
  15. return;
  16. }
  17. if (FAILED (Pshell->bindtoobject (Pitem, NULL, Iid_ishellfolder, (lpvoid*) &pfolder )))
  18. {
  19. return;
  20. }
  21. Pshell->release ();
  22. if (NULL = = Pfolder)
  23. {
  24. return;
  25. }
  26. ienumidlist* penum = NULL;
  27. if (FAILED (Pfolder->enumobjects (NULL, Shcontf_nonfolders, &penum)))
  28. {
  29. return;
  30. }
  31. Pitem = NULL;
  32. ULONG ulfetched = 0;
  33. WCHAR Szlnkpath[max_path] = {0};
  34. WCHAR Szlnkname[max_path] = {0};
  35. lpcwstr pszlnkname (L". lnk");
  36. Win32_find_dataw fd = {0};
  37. While (S_OK = = Penum->next (1, &pitem, &ulfetched))
  38. {
  39. SHGETDATAFROMIDLISTW (Pfolder, Pitem, Shgdfil_finddata, &FD, sizeof (FD));
  40. swprintf (Szlnkname, L"%s", fd.cfilename);
  41. if (0 = = wcscmp (WCSRCHR (szlnkname, L'. '), pszlnkname))
  42. {
  43. swprintf (Szlnkpath, L"%s//%s", szpath, Szlnkname);
  44. AfxMessageBox (CString (Szlnkpath));
  45. //parselnk2path (Szlnkpath);
  46. }
  47. }
  48. Penum->release ();
  49. Pfolder->release ();
  50. }
  51. The corresponding absolute path is obtained by the program's LNK path
  52. BOOL Parselnk2path (lpcwstr pszlnkname)
  53. {
  54. :: CoInitialize (NULL);
  55. ishelllink* Pshell = NULL;
  56. ipersistfile* pFile = NULL;
  57. if (S_OK = =:: CoCreateInstance (Clsid_shelllink, NULL, Clsctx_inproc_server, Iid_ishelllink, (lpvoid*) & Pshell))
  58. {
  59. if (S_OK = = Pshell->queryinterface (Iid_ipersistfile, (lpvoid*) &pfile))
  60. {
  61. Pfile->load (Pszlnkname, stgm_readwrite);
  62. TCHAR Szpath[max_path] = {0};
  63. Pshell->getpath (szpath, MAX_PATH, NULL, slgp_uncpriority);
  64. AfxMessageBox (CString (szpath));
  65. }
  66. }
  67. Pshell->release ();
  68. Pfile->release ();
  69. :: CoUninitialize ();
  70. return TRUE;
  71. }

http://blog.csdn.net/visualeleven/article/details/6433330

Enumerates the desktop application LNK paths and obtains the corresponding program's absolute path (using the Shgetdesktopfolder function enumeration, and then using COM to query the Ishellfolder,ishelllink and IPersistFile interfaces)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.