I want to open a *.conf file. I want to open this file with the standard Windows editor (e.g., notepad.exe).
I currently have this ShellExecute code:
How do I open a file with the default text editor?
You need to use ShellExecuteEx and use the lpClass
member of SHELLEXECUTEINFO to specify that you want to treat the file as a text file. Like this:
procedure OpenAsTextFile(const FileName: string);
var
sei: TShellExecuteInfo;
begin
ZeroMemory(@sei, SizeOf(sei));
sei.cbSize := SizeOf(sei);
sei.fMask := SEE_MASK_CLASSNAME;
sei.lpFile := PChar(FileName);
sei.lpClass := '.txt';
sei.nShow := SW_SHOWNORMAL;
ShellExecuteEx(@sei);
end;
Pass the full path to the file as FileName
.