注册表中的一个文件类型怎么删除
问题是这样的,我用DeleteSubKeyTree()可一直都删不掉(比如.MP3),都不知道为什么。
很纠结。
系统:Windows8.1
该注册表项定义是这样的
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mp3]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mp3\UserChoice]
"Hash"="ZrsPmXRsjQc="
"ProgId"="Audio.MP3"
而我写的代码
RegistryKey regKey= Registry.CurrentUser;
string SubKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts";
RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
string[] subKeys = optionKey.GetSubKeyNames();
foreach (string akey in subKeys)
{
if (akey.ToUpper() == ".MP3")
{
RegistryKey _VRPkey = optionKey.OpenSubKey(akey,true);
if(_VRPkey!=null)
optionKey.DeleteSubKeyTree(akey);
//optionKey.Close();
return true;
}
}
高手能支招这是错在哪了?
如果说用来关联文件的话,有什么好的支招么。
仅仅在Registry.ClassesRoot设置好像不给力啊,注册表是改了,但关联还是错误的。
可能是我曾经对这类型的文件右键 更改 过打开方式的缘故?
Win81很纠结
请求大神
------解决方案--------------------http://blog.sina.com.cn/s/blog_6532295a0100q8hk.html
------解决方案--------------------这是一个开机启动的例子,可以参考这个来实现
public static bool AutoRun(bool param)
{
string strName = Application.ExecutablePath;
string strNewName = strName.Substring(strName.LastIndexOf("\\") + 1, strName.LastIndexOf(".") - strName.LastIndexOf("\\") - 1);
//指定文件是否存在
if (!System.IO.File.Exists(strName))
return false;
Microsoft.Win32.RegistryKey rkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (rk