本文整理自网络,侵删。
uses Registry;
function RegisterFileTypeCommand(fileExtension, menuItemText, target: string) : boolean;
var
reg: TRegistry;
fileType: string;
begin
result := false;
reg := TRegistry.Create;
with reg do
try
RootKey := HKEY_CLASSES_ROOT;
if OpenKey('.' + fileExtension, True) then
begin
fileType := ReadString('') ;
if fileType = '' then
begin
fileType := fileExtension + 'file';
WriteString('', fileType) ;
end;
CloseKey;
if OpenKey(fileType + '/shell/' + menuItemText + '/command', True) then
begin
WriteString('', target + ' "%1"') ;
CloseKey;
result := true;
end;
end;
finally
Free;
end;
end;
function UnRegisterFileTypeCommand(fileExtension, menuItemText: string) : boolean;
var
reg: TRegistry;
fileType: string;
begin
result := false;
reg := TRegistry.Create;
with reg do
try
RootKey := HKEY_CLASSES_ROOT;
if OpenKey('.' + fileExtension, True) then
begin
fileType := ReadString('') ;
CloseKey;
end;
if OpenKey(fileType + '/shell', True) then
begin
DeleteKey(menuItemText) ;
CloseKey;
result := true;
end;
finally
Free;
end;
end;
相关阅读 >>
Delphi xe6开发的android应用实现在线升级完成后自动安装apk代码(加说明)
更多相关阅读请进入《Delphi》频道 >>