Find the path of notepad.exe and mspaint.exe

前端 未结 11 1194
后悔当初
后悔当初 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:17

    Normally, you would just execute them. They are on the system path in every version of Windows.

    You can use ExpandEnvironmentStrings. The environment variable you want to expand is WINDIR.

    In the past you could have used GetWindowsDirectory or GetSystemDirectory, but I think they are deprecated.

    0 讨论(0)
  • 2021-01-31 10:20

    Since you tagged the question with WinAPI, I'd use SearchPath() e.g. the following will populate the variable path with the result.

    //Get the full path to notepad
    char path[MAX_PATH] = { 0 };
    LPSTR* ptr = NULL;
    DWORD dwRet = SearchPath(NULL, "notepad.exe", NULL, MAX_PATH, (LPSTR)path, ptr);
    
    0 讨论(0)
  • 2021-01-31 10:21

    Try opening a DOS prompt, change to the Windows folder and do:

    dir notepad.exe /s
    

    Long live DOS :)

    0 讨论(0)
  • 2021-01-31 10:22

    I think to start off small you should get the windir environment variable and look in the subfolders %windir%\system32\ for mspaint and notepad. Most likely they will be there.

    However if that fails, well then resort to a more brute force search.

    0 讨论(0)
  • 2021-01-31 10:22

    Go to the system32 folder and type "notepad.exe" into the 'File Name' bar.

    0 讨论(0)
提交回复
热议问题