如何預設特定檔案與特定EXE檔案關連 |
尚未結案
|
g9221712
高階會員 發表:145 回覆:344 積分:162 註冊:2006-07-06 發送簡訊給我 |
各位前輩:
可以幫我看看,如下我去註冊影音檔案與播放器軟體的關連,但好像不是每個副檔名都可以關連成功,也就是有的關連OK 有的又維持原播放程式程式並無法改變,不知道適合原因,請指教,謝謝您! [code delphi] // AFE // Associate an application with a file extension unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, registry, shlobj; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} uses UNT_MsWin; // registry, shlobj procedure RegisterFileType(ExtName: String; AppName: String); var reg: TRegistry; begin reg := TRegistry.Create; try reg.RootKey := HKEY_CLASSES_ROOT; reg.OpenKey('.' ExtName, True); reg.WriteString('', ExtName 'file'); reg.CloseKey; reg.CreateKey(ExtName 'file'); reg.OpenKey(ExtName 'file\DefaultIcon', True); reg.WriteString('', AppName ',0'); reg.CloseKey; reg.OpenKey(ExtName 'file\shell\open\command', True); reg.WriteString('', AppName ' "%1"'); reg.CloseKey; finally reg.Free; end; SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil); end; procedure RegisterVideoType(exe_PathAndFileName: String); begin RegisterFileType('rm', exe_PathAndFileName); RegisterFileType('rmvb', exe_PathAndFileName); RegisterFileType('avi', exe_PathAndFileName); RegisterFileType('mpg', exe_PathAndFileName); RegisterFileType('dat', exe_PathAndFileName); RegisterFileType('wmv', exe_PathAndFileName); RegisterFileType('3gp', exe_PathAndFileName); RegisterFileType('mp4', exe_PathAndFileName); RegisterFileType('mpeg', exe_PathAndFileName); end; procedure TForm1.Button1Click(Sender: TObject); var exe_PathAndFileName: string; begin exe_PathAndFileName := 'D:\Program Files\Programs\MM\KMPlayer\KMPlayerPortable\KMPlayerPortable.exe'; RegisterVideoType(exe_PathAndFileName); end; procedure TForm1.Button2Click(Sender: TObject); var exe_PathAndFileName: string; begin exe_PathAndFileName := 'C:\Program Files (x86)\VideoLAN\VLC\vlc.exe'; RegisterVideoType(exe_PathAndFileName); end; procedure TForm1.Button3Click(Sender: TObject); var exe_PathAndFileName: string; begin exe_PathAndFileName := 'C:\Program Files\Windows Media Player\wmplayer.exe'; RegisterVideoType(exe_PathAndFileName); end; end. [/code]
------
「人們所以覺得寂寞,是因為他們會築牆,卻不會搭橋。」 程式寫的越久,卻發現自己越來越不會寫程式! |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |