📄 xregistry.pas
字号:
unit xRegistry;
interface
uses Windows, SysUtils, Registry;
function GetAssociatedExecutable(FileExt: string; var FileDesc, MIMEType: string; sCommand: string = 'open'): string;
function SetAssociatedExecutable(FileExt, Filetype, FileDesc, MIMEType, ExecutablePath: string; sCommand: string = 'open'): Boolean;
function ReadKeyDefaultValue(REG: TRegistry; const sKey: string): string;
procedure WriteKeyDefaultValue(REG: TRegistry; const sKey, sValue: string);
implementation
uses xStrings;
function GetAssociatedExecutable(FileExt: string; var FileDesc, MIMEType: string; sCommand: string): string;
var
Filetype: string;
begin
Result := '';
if FileExt = '' then Exit;
if FileExt[1] <> '.' then Filetype := FileExt;
with TRegistry.Create do
try
RootKey := HKEY_CLASSES_ROOT;
if Filetype = '' then
begin
if OpenKey(FileExt, False) then
begin
Filetype := ReadString('');
MIMEType := ReadString('Content Type');
CloseKey;
end;
end;
if Filetype = '' then Exit;
if OpenKey(Filetype, False) then
begin
FileDesc := ReadString('');
if OpenKey('shell\' + sCommand + '\command', False) then
begin
Result := Trim(ReadString(''));
// Truncate the paramters '%1' token from executable path
// Ex. 'c:\winword.exe %1' -> 'c:\winword.exe'
// result := '"' + result + '"';
if Length(Result) > 1 then
begin
Result := Trim(ExpandEnvStr(TrimParameters(unquotestring(Result))));
end;
end;
CloseKey;
end;
finally
Free;
end;
end;
// FileType, FileDesc and MIMEType is optional.
function SetAssociatedExecutable(FileExt, Filetype, FileDesc, MIMEType, ExecutablePath: string; sCommand: string): Boolean;
begin
Result := False;
if (FileExt = '') or (ExecutablePath = '') then Exit;
// 絋玂 FileExt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -