Find the path of notepad.exe and mspaint.exe

前端 未结 11 1177
后悔当初
后悔当初 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: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);
    

提交回复
热议问题