[原]在windows右键菜单中加上关联

  • 主题发起人 主题发起人 SUNSTONE的Delphi笔记
  • 开始时间 开始时间
S

SUNSTONE的Delphi笔记

Unregistered / Unconfirmed
GUEST, unregistred user!
shellcommandregister.gif



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;

作者:sunstone 发表于2009/10/22 21:24:00 原文链接
阅读:744 评论:0 查看评论

查看更多...
 

Similar threads

后退
顶部