如何处理应用程序中的文件关联?

发布于 2024-11-24 05:08:44 字数 279 浏览 2 评论 0原文

我知道安装程序可以在安装过程中为您的应用程序设置文件关联,因此,如果您有自己的文件类型与您的应用程序一起打开,它将被设置为执行此操作,并且关联的文件将在 Windows 中拥有自己的图标你定义。

无论如何,我希望能够直接从我的应用程序中的首选项表单设置/删除我的应用程序将使用的文件类型。

需要什么方法来做到这一点,我正在沿着注册表的思路思考,但是如果注册表是正确的方法,那么我们要使用什么键/值等呢?

感谢一些建议和提示,它在 XP/Vista/7 上运行也很重要。

提前致谢。

I know Installers can setup File Associations for your Application during the installation process, so if you have your own File types that open with your Application, it will be setup to do that, and also the associated File will have its own icon in Windows what you define.

Anyway, I would like to be able to Set/Remove the File types my Application will use, directly from the preferences form in my Application.

What methods are needed to do this, I am thinking along the lines of the Registry, but then what Keys/Values etc are we to work with, if Registry is the way to go?

Appreciate some advice and tips, It is also important that it works on XP/Vista/7.

Thanks in Advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

酒废 2024-12-01 05:08:47

您可以从 shell 运行以下命令
http://support.microsoft.com/kb/184082


您可以在注册表中进行输入,如以下链接所示
http://www.daycounter.com/LabBook/Changing -File-Associations-With-Registry-Editor.phtml

You can run the following command from your shell
http://support.microsoft.com/kb/184082

or
you can make the entry in registry as shown in the following link
http://www.daycounter.com/LabBook/Changing-File-Associations-With-Registry-Editor.phtml

春夜浅 2024-12-01 05:08:46

尝试此单元将某个扩展名与 exe 关联,删除注册表中的条目以取消注册。

unit utils; 

interface 
uses Registry, ShlObj, SysUtils, Windows; 

procedure RegisterFileType(cMyExt, cMyFileType, cMyDescription, ExeName: string; IcoIndex: integer; DoUpdate: boolean = false); 

implementation 

procedure RegisterFileType(cMyExt, cMyFileType, cMyDescription, ExeName: string; IcoIndex: integer; DoUpdate: boolean = false); 
var 
   Reg: TRegistry; 
begin 
  Reg := TRegistry.Create; 
  try 
    Reg.RootKey := HKEY_CLASSES_ROOT; 
    Reg.OpenKey(cMyExt, True); 
    // Write my file type to it. 
    // This adds HKEY_CLASSES_ROOT\.abc\(Default) = 'Project1.FileType' 
    Reg.WriteString('', cMyFileType); 
    Reg.CloseKey; 
    // Now create an association for that file type 
    Reg.OpenKey(cMyFileType, True); 
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\(Default) 
    //   = 'Project1 File' 
    // This is what you see in the file type description for 
    // the a file's properties. 
    Reg.WriteString('', cMyDescription); 
    Reg.CloseKey;    // Now write the default icon for my file type 
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\DefaultIcon 
    //  \(Default) = 'Application Dir\Project1.exe,0' 
    Reg.OpenKey(cMyFileType + '\DefaultIcon', True); 
    Reg.WriteString('', ExeName + ',' + IntToStr(IcoIndex)); 
    Reg.CloseKey; 
    // Now write the open action in explorer 
    Reg.OpenKey(cMyFileType + '\Shell\Open', True); 
    Reg.WriteString('', '&Open'); 
    Reg.CloseKey; 
    // Write what application to open it with 
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\Shell\Open\Command 
    //  (Default) = '"Application Dir\Project1.exe" "%1"' 
    // Your application must scan the command line parameters 
    // to see what file was passed to it. 
    Reg.OpenKey(cMyFileType + '\Shell\Open\Command', True); 
    Reg.WriteString('', '"' + ExeName + '" "%1"'); 
    Reg.CloseKey; 
    // Finally, we want the Windows Explorer to realize we added 
    // our file type by using the SHChangeNotify API. 
    if DoUpdate then SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil); 
  finally 
    Reg.Free; 
  end; 
end; 

end.

注册表无疑是处理事情的方法......

try this unit to associate a certain extension to an exe remove the entries made in registry to unregister.

unit utils; 

interface 
uses Registry, ShlObj, SysUtils, Windows; 

procedure RegisterFileType(cMyExt, cMyFileType, cMyDescription, ExeName: string; IcoIndex: integer; DoUpdate: boolean = false); 

implementation 

procedure RegisterFileType(cMyExt, cMyFileType, cMyDescription, ExeName: string; IcoIndex: integer; DoUpdate: boolean = false); 
var 
   Reg: TRegistry; 
begin 
  Reg := TRegistry.Create; 
  try 
    Reg.RootKey := HKEY_CLASSES_ROOT; 
    Reg.OpenKey(cMyExt, True); 
    // Write my file type to it. 
    // This adds HKEY_CLASSES_ROOT\.abc\(Default) = 'Project1.FileType' 
    Reg.WriteString('', cMyFileType); 
    Reg.CloseKey; 
    // Now create an association for that file type 
    Reg.OpenKey(cMyFileType, True); 
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\(Default) 
    //   = 'Project1 File' 
    // This is what you see in the file type description for 
    // the a file's properties. 
    Reg.WriteString('', cMyDescription); 
    Reg.CloseKey;    // Now write the default icon for my file type 
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\DefaultIcon 
    //  \(Default) = 'Application Dir\Project1.exe,0' 
    Reg.OpenKey(cMyFileType + '\DefaultIcon', True); 
    Reg.WriteString('', ExeName + ',' + IntToStr(IcoIndex)); 
    Reg.CloseKey; 
    // Now write the open action in explorer 
    Reg.OpenKey(cMyFileType + '\Shell\Open', True); 
    Reg.WriteString('', '&Open'); 
    Reg.CloseKey; 
    // Write what application to open it with 
    // This adds HKEY_CLASSES_ROOT\Project1.FileType\Shell\Open\Command 
    //  (Default) = '"Application Dir\Project1.exe" "%1"' 
    // Your application must scan the command line parameters 
    // to see what file was passed to it. 
    Reg.OpenKey(cMyFileType + '\Shell\Open\Command', True); 
    Reg.WriteString('', '"' + ExeName + '" "%1"'); 
    Reg.CloseKey; 
    // Finally, we want the Windows Explorer to realize we added 
    // our file type by using the SHChangeNotify API. 
    if DoUpdate then SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil); 
  finally 
    Reg.Free; 
  end; 
end; 

end.

Registry is defenetly the way to go with things...

妖妓 2024-12-01 05:08:46

在您的应用程序中,您最好使用每用户存储进行文件关联。如果您使用系统范围的注册表位置,那么您需要提升才能应用更改。这不是您应该在标准用户应用程序中执行的操作。

将注册表设置存储在:

HKEY_CURRENT_USER\SOFTWARE\Classes

下的条目格式与下的完全相同

HKEY_LOCAL_MACHINE\SOFTWARE\Classes

From your app you'd be better to use the per-user store for file associations. If you use the system wide registry location then you'd need to elevate in order to apply changes. That's not something you should do in a standard user app.

Store the registry settings under:

HKEY_CURRENT_USER\SOFTWARE\Classes

The format of entries under there is exactly the same as under

HKEY_LOCAL_MACHINE\SOFTWARE\Classes
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文