delphi和INNO SETUP 文件关联操作
procedure TForm1.Button1Click(Sender: TObject);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
{在注册表中添加我们虚拟的 .tst 格式, 并指定默认项的值是 TestFile}
reg.OpenKey('.tst', True);
reg.WriteString('', 'TestFile');
reg.CloseKey;
{文件打开关联}
reg.OpenKey('TestFile\shell\open\command', True);
reg.WriteString('', ParamStr(0) + ' %1');
reg.CloseKey;
{文件图标关联}
reg.OpenKey('TestFile\DefaultIcon', True);
reg.WriteString('', ParamStr(0) + ',0');
reg.CloseKey;
reg.Free;
{刷新图标显示}
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
{清除上面的设置}
procedure TForm1.Button2Click(Sender: TObject);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
reg.DeleteKey('.tst');
reg.DeleteKey('TestFile');
reg.Free;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
也可以通过手动设置文件关联,方法是:打开一个文件夹--工具--文件夹选项--“文件类型”选项卡---单击下面的“高级”。
用 INNO 是很方便的,不要写代码,直接用 [Registry] 段就行了。比如:
[Registry]
Root: HKCR; Subkey: "Real 媒体文件"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey
Root: HKCR; Subkey: "Real 媒体文件\DefaultIcon"; ValueType: String; ValueData: "{app}\abc.ICO";Flags: uninsdeletekey
Root: HKCR; Subkey: "Real 媒体文件\shell\open\command"; ValueType: String; ValueData: "{app}\myplayer.exe %1";Flags: uninsdeletekey
Root: HKCR; Subkey: "Real 媒体文件\shell\用 My Player 打开(&O)\command"; ValueType: String; ValueData: "{app}\myplayer.exe %1";Flags: uninsdeletekey
Root: HKCR; Subkey: "*.rmvb"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey
Root: HKCR; Subkey: "*.rm"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey
Root: HKCR; Subkey: "*.ra"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
{在注册表中添加我们虚拟的 .tst 格式, 并指定默认项的值是 TestFile}
reg.OpenKey('.tst', True);
reg.WriteString('', 'TestFile');
reg.CloseKey;
{文件打开关联}
reg.OpenKey('TestFile\shell\open\command', True);
reg.WriteString('', ParamStr(0) + ' %1');
reg.CloseKey;
{文件图标关联}
reg.OpenKey('TestFile\DefaultIcon', True);
reg.WriteString('', ParamStr(0) + ',0');
reg.CloseKey;
reg.Free;
{刷新图标显示}
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
{清除上面的设置}
procedure TForm1.Button2Click(Sender: TObject);
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
reg.DeleteKey('.tst');
reg.DeleteKey('TestFile');
reg.Free;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
也可以通过手动设置文件关联,方法是:打开一个文件夹--工具--文件夹选项--“文件类型”选项卡---单击下面的“高级”。
用 INNO 是很方便的,不要写代码,直接用 [Registry] 段就行了。比如:
[Registry]
Root: HKCR; Subkey: "Real 媒体文件"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey
Root: HKCR; Subkey: "Real 媒体文件\DefaultIcon"; ValueType: String; ValueData: "{app}\abc.ICO";Flags: uninsdeletekey
Root: HKCR; Subkey: "Real 媒体文件\shell\open\command"; ValueType: String; ValueData: "{app}\myplayer.exe %1";Flags: uninsdeletekey
Root: HKCR; Subkey: "Real 媒体文件\shell\用 My Player 打开(&O)\command"; ValueType: String; ValueData: "{app}\myplayer.exe %1";Flags: uninsdeletekey
Root: HKCR; Subkey: "*.rmvb"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey
Root: HKCR; Subkey: "*.rm"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey
Root: HKCR; Subkey: "*.ra"; ValueType: String; ValueData: "Real 媒体文件";Flags: uninsdeletekey