如何将程序与文件类型关联,但仅限当前用户?
因此,如果不强制可怜的用户输入其管理员密码,我就无法将我的程序与特定文件类型关联起来(对于家庭用户来说可能没问题,但对于企业环境中的用户来说这是一个巨大的问题)。在这种情况下,唯一的解决方案是仅为当前用户进行关联。
我已经尝试过了,但有些东西不起作用。
如果我理解正确的话,我必须在 ctCurUserFileExt 中编写一个类似(比方说)“.mp3”的密钥,并在其中写入类似“my_file”的内容。然后在 ctCurUserClases 中我添加一个如下所示的键:
WriteReg_String(RootKey, ctCurUserClases+ 'my_file\shell\open\command', '', Application.ExeName+ ' "%L"', TRUE)
但是,当我双击该文件时,Windows 会询问我应该使用哪个应用程序打开它。
这是常数:
CONST
RootKey= 'HKEY_CURRENT_USER';
ctCurUserFileExt= '\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\';
ctCurUserClases = '\Software\Classes\';
So, I cannot associate my program with a specific file type without forcing the poor user to enter its admin password (it may be ok for home users, but it is a gigantic problem for users in a corporate env). In this case the only solution is to make the association only for the current user.
I have tried that but something is not working.
If i understand correctly I have to write a key like (let's say) '.mp3' in ctCurUserFileExt and write in it something like 'my_file'. Then in ctCurUserClases I add a key like this:
WriteReg_String(RootKey, ctCurUserClases+ 'my_file\shell\open\command', '', Application.ExeName+ ' "%L"', TRUE)
However, when I double click the file, Windows asks me with which application should it open it.
Here are the constant:
CONST
RootKey= 'HKEY_CURRENT_USER';
ctCurUserFileExt= '\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\';
ctCurUserClases = '\Software\Classes\';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想为每个用户注册关联,请将您的数据写入
如果您只想为当前用户注册关联,请将您的数据写入
这是后者的操作方法:
这将关联 .myfile 文件,称为“My非常自己的文本文件类型”,这样它们将具有 notepad.exe 的图标,并由 notepad.exe 打开。最后一行告诉资源管理器“重新加载”自身以反映对文件关联所做的更改。例如,资源管理器文件列表视图将更新。 WinAPI函数
SHChangeNotify
在ShlObj.pas
中声明,因此您需要使用ShlObj
。请注意,
shell\open\command
中的%1
将扩展到当前文件。例如,如果双击C:\some dir\test.myfile
,则资源管理器将执行命令If you want to register the association for every user, write your data to
If you want to register the association for the current user only, write your data to
This is how to do the latter:
This will associate .myfile files, called "My Very Own Text File Type" so that they will have the icon of notepad.exe and will be opened by notepad.exe. The last line tells Explorer to 'reload' itself to reflect the changes made to the file associations. For instance, Explorer file list views will update. The WinAPI function
SHChangeNotify
is declared inShlObj.pas
, so you need touses ShlObj
.Notice that the
%1
inshell\open\command
will expand to the current file. For instance, if you double-click onC:\some dir\test.myfile
, then Explorer will execute the command您是否考虑过按照 http://support.microsoft.com/kb 在 HKEY_CURRENT_USER\Software\Classes 下设置它/257592
Have you looked at setting it under HKEY_CURRENT_USER\Software\Classes as per http://support.microsoft.com/kb/257592