Find the path of notepad.exe and mspaint.exe

前端 未结 11 1297
后悔当初
后悔当初 2021-01-31 09:45

What is the best way to find out where notepad.exe and mspaint.exe are that will work across various versions of Windows?

Should I get the Windows directory via SHGetFol

11条回答
  •  轮回少年
    2021-01-31 10:13

    In short I find that the best approach is to check the Windows\System32 directory and the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths registry keys.

    More generally I find that the best approach is to mimic ShellExecuteEx.

    Taken from:
    Application Registration (Windows)
    https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121(v=vs.85).aspx

    The file is sought in the following locations:
    •The current working directory.
    •The Windows directory only (no subdirectories are searched).
    •The Windows\System32 directory.
    •Directories listed in the PATH environment variable.
    •Recommended: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths

    A further possibly is to check Start Menu\Programs\Accessories, by using SHGetFolderPath with CSIDL_STARTMENU := 11 and CSIDL_COMMON_STARTMENU := 22, and retrieve the targets from the lnk files.

提交回复
热议问题