让自己的软件实现双击打开文件(修改注册表设置关联)

让自己的软件实现双击打开文件
作者:帅宏军

复制代码
unit shjAssociateFileType;

interface
uses Windows, Registry;
{将文件类型strFileExtension与程序strExeFileName相关联,strDiscription为文件类型说明}
function AssignToProgram(const strFileExtension, strDiscription, strExeFileName: string ): boolean;

implementation
{将文件类型strFileExtension与程序strExeFileName相关联,strDiscription为文件类型说明}
function AssignToProgram(const strFileExtension, strDiscription, strExeFileName: string ): boolean;
var
  regFile: TRegistry;
begin
  //建立一个Registry实例
  regFile := TRegistry.Create;
  with regFile do
  begin
    //设置根键值为HKEY_CLASSES_ROOT
    RootKey := HKEY_CLASSES_ROOT;
    //创建或者打开扩展名自动关联注册键
    OpenKey( '.' + strFileExtension, true);
    //设置扩展名自动关联
    WriteString('', strFileExtension + '_Auto_File');
    //关闭键
    CloseKey;
    //创建或者打开打开自动关联键
    OpenKey(strFileExtension + '_Auto_File', true);
    //设置文件类型说明
    WriteString('', strDiscription);
    //关闭键
    CloseKey;
    //创建或打开关联程序键
    OpenKey(strFileExtension + '_Auto_File\shell\open\command', true);
    //设置关联程序(注意:%1加上双引号,可以解决文件路径中含空格的问题)
    WriteString('',strExeFileName + ' "%1"');
    //关闭键
    CloseKey;
    //打开默认图标键
    OpenKey(strFileExtension + '_Auto_File\defaulticon',true);
    //关联默认图标
    WriteString('', strExeFileName + ',0');
    //释放
    Free;
    Result := True;
  end;
end;
end.
复制代码

http://blog.csdn.net/shuaihj/article/details/7046515

posted @   findumars  Views(1229)  Comments(0Edit  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
历史上的今天:
2012-04-01 几个能用的C语言IO读写数据的例子
点击右上角即可分享
微信分享提示