讓自己的軟體實現雙擊開啟檔案

來源:互聯網
上載者:User

讓自己的軟體實現雙擊開啟檔案

作者:帥宏軍

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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.