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
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.
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);
Try opening a DOS prompt, change to the Windows folder and do:
dir notepad.exe /s
Long live DOS :)
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.
Go to the system32 folder and type "notepad.exe" into the 'File Name' bar.