c++ - Windows系统中如何获取快捷方式文件对应的程序路径?
阿神
阿神 2017-04-17 14:43:31
0
1
1103
  1. 目标:获取快捷方式文件对应的程序(文件)路径

  2. 环境: Windows 10, Visual Studio 2015, C++

  3. 问题:

    3.1 windows提供了获取路径的API, 参见[ISHellLink::GetPath][1]。
    3.2 使用SLGP_SHORTPATH作为参数能够解决大部分问题,但是对于涉及到重定向的,该函数返回的是错误的路径。
        如“桌面/A.lnk”快捷方式文件对应的程序是“C:\\Program Files\\A\\A.exe”,但是使用该参数后,返回的路径是“C:\\Program Files (x86)\\A\\A.exe”。
    3.3 使用SLGP_RAWPATH作为参数,能获取长路径,这样可以对有环境变量的长路径进行expand,目前是这个思路。但是函数有时会返回空字符串,但是MSDN上并没有详细的解释。
    
    
    
阿神
阿神

闭关修行中......

reply all(1)
黄舟

Don’t use ShortPath, 8.3 short file names are from the DOS era. Disable 64-bit file redirection,
Wow64DisableWow64FsRedirection. Restore 64-bit file system redirection, Wow64RevertWow64FsRedirection function. Whenever a successful call to disable redirection completes the required operations, redirection must be restored immediately to avoid problems.
Or if you compile a 64-bit program on a 64-bit system, there will be no redirection.
You can try to get RawPath first, and if it fails, call it again without RawPath. Note that RawPath may contain environment variables, requiring ExpandEnviron to expand it. Also you can try this library: https://github.com/libyal/liblnk

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template