win7下永远解决“右键某文件----选择打开方式----出现两个记事本”的情况

clip_image002

如上图,

很多人会发现在右键菜单中会出现两个 “记事本”的情况。其实这也是很正常的一件事,因为在我们系统windows文件夹(C:\Windows)和system32文件夹(C:\Windows\System32)下面各有一个notepad.exe程序,系统在注册应用程序和文件关联打开方式的时候,分别使用了它们,但是打开方式又要读取这两个地方,这就出来两个记事本了,呵呵,我这么一说应该就明白是什么回事了!

我做了一个批处理,用来处理这个问题,把里面的代码复制粘贴到文本文件,保存为后缀.bat的文件,执行就可以了。

@echo off

if exist "%systemroot%\notepad.exe" set Npath="%systemroot%\notepad.exe %%"1

if not exist "%systemroot%\notepad.exe" set Npath="%systemroot%\system32\notepad.exe %%"1

reg add "HKCR\txtfile\shell\open\command" /ve /d %Npath% /t REG_SZ /f

reg add "HKCR\Applications\notepad.exe\shell\open\command" /ve /d %Npath% /t REG_SZ /f

reg add "HKCR\SystemFileAssociations\text\shell\open\command" /ve /d %Npath% /t REG_SZ /f

经我测试,再加上翻阅资料,上述源码有误,应该是:

@echo off

if exist "%systemroot%\notepad.exe" set Npath="%systemroot%\notepad.exe %"1

if not exist "%systemroot%\notepad.exe" set Npath="%systemroot%\system32\notepad.exe %"1

reg add "HKCR\txtfile\shell\open\command" /ve /d %Npath% /t REG_SZ /f

reg add "HKCR\Applications\notepad.exe\shell\open\command" /ve /d %Npath% /t REG_SZ /f

reg add "HKCR\SystemFileAssociations\text\shell\open\command" /ve /d %Npath% /t REG_SZ /f

clip_image004

命令简单介绍:

if exist "%systemroot%\notepad.exe" set Npath="%systemroot%\notepad.exe %"1

这句话是设置一个变量: Npath="%systemroot%\notepad.exe %"1,这个变量将写入注册表.

HKCR\txtfile\shell\open\command

HKCR\Applications\notepad.exe\shell\open\command

HKCR\SystemFileAssociations\text\shell\open\command

下面显示注册表HKCR\txtfile\shell\open\command的情况:

clip_image006

%1 表示参数..

比如你想打开1.txt,就是用 命令:notepad 1.txt搞定。

这个方法算是解决了txt后缀文件打开方式出现两个文件夹的问题.

但是ini文件却没办法根据这个方法来解决.ini文件选择右键打开也是出现两个记事本选项.

clip_image008

我们找到HKEY_CLASSES_ROOT\inifile\shell\open\command这个项 ,发现只有一个一个数值:

clip_image010

按理说,他应该只有一个打开记事本才对啊.我们再去这个项下面看看:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ini\OpenWithList

发现他是没有项目了.:

clip_image012

而下面的

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.ini\OpenWithProgids

有一个项值: inifile..这说明了它是根据inifile 注册项来查找打开方式的.

clip_image014

这只能说明存在两种可能

①除了之前HKEY_CLASSES_ROOT\inifile项,还存在另一个inifile项。

经过查找,发现了这个

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\inifile

clip_image016

但是这里还是只有一个数据项,跟HKEY_CLASSES_ROOT\inifile的数据是一致的。

②那么就是第二种可能,还有别的.ini注册表 控制了这个后缀类型选择。

经过查找,有好几个.ini 项(就不全部列出来了)

1) HKEY_CLASSES_ROOT\.ini

clip_image018

原来是PerceivedType在作怪。它默认是text。

2)

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\.ini(没什么用)

3)

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.ini

clip_image020

它也默认是text

PerceivedType是说接受或者感知的类型 是注册表里的键值
比如 在注册表中,只要有字符串值"PerceivedType"="text"这一个项目,该文件的右键选择项中就会出现text的选择项。

这个text 就是对应着下面这一项:

HKEY_CLASSES_ROOT\SystemFileAssociations\text

还记得他吗?这就是上文在修改txt右键出现两个记事本的时候,修改的注册表项了。

他的值在上文已经设置过了,是”%systemroot%\notepad.exe” 见下表

clip_image022

这也就解释了为什么inf文件也有两个记事本了。见下图:

clip_image024

总结:

我们在设置txt后缀打开类型的时候,

设置了

HKEY_CLASSES_ROOT\SystemFileAssociations\text\shell\open\command

=%systemroot%\notepad.exe

这就导致text类型直接映射到c:\Windows\notepad.exe

这时候包括ini文件inf文件在内的所有PerceivedType=text的文件类型映射到了c:\Windows\notepad.exe。

ini,inf文件的打开类型已经映射到了c:\Windows\System32\notepad.exe

这时候就会右键打开---出现两个记事本选项。。

解决的根本之道就是,将

HKEY_CLASSES_ROOT\SystemFileAssociations\text\shell\open\command

=%systemroot%\System32\notepad.exe

。。。

请使用命令:

@echo off

set Npath="%systemroot%\system32\notepad.exe %"1

reg add "HKCR\txtfile\shell\open\command" /ve /d %Npath% /t REG_SZ /f

reg add "HKCR\Applications\notepad.exe\shell\open\command" /ve /d %Npath% /t REG_SZ /f

reg add "HKCR\SystemFileAssociations\text\shell\open\command" /ve /d %Npath% /t REG_SZ /f

最后我们看看所谓的ini文件:

clip_image026

---end

转载于:https://my.oschina.net/liangshao/blog/114559

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值