用脚本文件简单修改注册表

用.VBS脚本,也就是SCRIPT 脚本文件对注册表进行修改。如果您的爱机不支持VBSCRIPT,那么请您直接阅读第二部分。下面我通过一个例子自来解释脚本文件:

Windows Script Host Sample Script


You have a royalty-free right to use, modify, reproduce and distribute


the Sample Application Files (and/or any modified version) in any way


you find useful, provided that you agree that Microsoft has no warranty,


obligations or liability for any Sample Application Files.


————————————————————————



This sample demonstrates how to write/delete entries in the registry.


L_Welcome_MsgBox_Message_Text = “此脚本显示如何创建和删除注册表项。”


L_Welcome_MsgBox_Title_Text = “Windows Scripting Host 范例”



Call Welcome()


********************************************************************************


*


* Registry related methods.


*


 


Dim WSHShell


Set WSHShell = WScript.CreateObject(“WScript.Shell”)


 


WSHShell.Popup “创建项 HKCU\MyRegKey 数值为 Top level key”


WSHShell.RegWrite “HKCU\MyRegKey\”, “Top level key”


 


WSHShell.Popup “创建项 HKCU\MyRegKey\Entry 数值为 Second level key”


WSHShell.RegWrite “HKCU\MyRegKey\Entry\”, “Second level key”


 


WSHShell.Popup “将数值项 HKCU\MyRegKey\Value 设为 REG_SZ 1”


WSHShell.RegWrite “HKCU\MyRegKey\Value”, 1


 


WSHShell.Popup “将数值项 HKCU\MyRegKey\Entry 设为 REG_DWORD 2”


WSHShell.RegWrite “HKCU\MyRegKey\Entry”, 2, “REG_DWORD”


 


WSHShell.Popup “将数值项 HKCU\MyRegKey\Entry\Value1 设为 REG_BINARY 3”


WSHShell.RegWrite “HKCU\MyRegKey\Entry\Value1”, 3, “REG_BINARY”


 


WSHShell.Popup ot;删除 HKCU\MyRegKey\Entry\Value1 数值”


WSHShell.RegDelete “HKCU\MyRegKey\Entry\Value1”


 


WSHShell.Popup “删除 HKCU\MyRegKey\Entry 项”


WSHShell.RegDelete “HKCU\MyRegKey\Entry\”


 


WSHShell.Popup “删除 HKCU\MyRegKey 项”


WSHShell.RegDelete “HKCU\MyRegKey\”


 


********************************************************************************


*


* Welcome


*


Sub Welcome()


Dim intDoIt


 


intDoIt = MsgBox(L_Welcome_MsgBox_Message_Text, _


vbOKCancel + vbInformation, _


L_Welcome_MsgBox_Title_Text )


If intDoIt = vbCancel Then


WScript.Quit


End If


End Sub


1.在上例中,单引号后面是注释.


2. L_Welcome_MsgBox_Message_Text = “此脚本显示如何创建和删除注册表项。”


L_Welcome_MsgBox_Title_Text = “Windows Scripting Host 范例”


这两句是提示.


3. 用 Set WSHShell = WScript.CreateObject(“WScript.Shell”),定义一个对象WSHSHELL 为WScript.Shell,


 


4.WELCOME()是一个确认对话框.


5. WSHShell.Popup “创建项 HKCU\MyRegKey 数值为 Top level key” 是声明要修改的注册表项.


WSHShell.RegWrite “HKCU\MyRegKey\”, “Top level key” 在HKCU下面创建MYREGKEY子键,读者也可以根据自己实际情况修改键名、指定路径。


6、REG_SZ为字符串,要用引号引起来,REG_DWORD 为0—2147483647之间整数,REG_BINARY与之范围相同。


7、需要注意的是,若结尾是“\”则创建一个主键(项),将其默认值设为逗号后面的值项,若结尾不是“\”,则在前一个“\”后面的项中建立所设立的VALUE,逗号后面为其值。


8、WSHShell.RegDelete与WSHShell.RegWrite大致相同,只是功能相反。


各位可以将上面文档复制,存为FILENAME.VBS,然后双击即可。



用INF 脚本修改注册表。同样我先举一个例子,然后做详细讲解。



[VERSION]


SIGNATURE=$CHICAGO$

#p#副标题#e#


 


[DEFAULTINSTALL]


ADDREG=MY.ADD.REG


DELREG=MY.DEL.REG


 


[MY.ADD.REG]


HKLM,SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\WINLOGON,AUTOADMINLOGON,0,”0”


HKCU,CONTROL PANEL\DESKTOP,SMOOTHSCROLL,1,01,00,00,00


HKCU,CONTROL PANEL\DESKTOP,SCREENSAVEUSEPASSWORD,1,00,00,00,00


 


[MY.DEL.REG]


HKCU,MYKEY


HKLM,SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\WINLOGON,DEFAULTUSERNAME


HKLM,SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\WINLOGON,DEFAULTUSERNAME


 


1.[VERSION] 是文件头。


SIGNATURE=$CHICAGO$ 是指针对WINDOWS(CHICAGO是WINDOWS95的内部名称)


要编辑注册表必须以这两句开头。


  2、[DEFAULTINSTALL]段指出INF文件包含的其他段,ADDREG 和DELREG是键,有特殊意义,他指出要添加或删除的注册表项段名


  3、WINDOWS98总是先处理DELREG段,后处理ADDREG段,这可能会对我们的应用有所帮助。


  [MY.ADD.REG]


  HKCU,MYKEY,MYVALUE,0,“STRING” 添加名为MYVALUE的字符串值项到键MYKEY下,其值设为STRING


  HKCU,MYKEY,MYVALUE,,STRING 添加名为MYVALUE的字符串值项到MYKEY,将其值设为STRING


  HKCU,MYKEY,MYVALUE,1,77,34,05,20添加名为MYVALUE的二进制值项到键MYKEY下,其值设为二进制值77,34,05,20


  HKCU,MYKEY,0,”DEFAULT VALUE” 设置键MYKEY的缺省值项为字符串DEFAULT VALUE


  HKCU,MYKEY,,”DEFAULT VALUE” 设置键MYKEY的缺省值项并将其值设为字符串DEFAULT VALUE


  HKCU,MYKEY 添加注册表键MYKEY但不设置其值


 


  [MY.DEL.REG]


  HKCU,MYKEY,MYVALUE 从键MYKEY 中删除值项MYVALUE


  HKCU,MYKEY 删除键MYKEY及其全部子键,即删除全部分支.


 


  下面是一个自动清除MRU记录的INF文件:


  CLEAN.INF


  [VERSION]


  SIGNATURE=$CHICAGO$


 


  [DEFAULTINSTALL]


  DELREG=DELTEGKEY


 


  [DELREGKEY]


  HKCU,”SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\DOC FIND SPEC MRU”,


  HKCU, SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\FINDCOMPUTERMRU,


  HKCU, SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\RECENTDOCS,


  HKCU, SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\EXPLORER\RUNMRU


 


  清除MRU和WINDOWS\RENCENT 的批处理文件


  CLEAN.BAT


  @ECHO OFFwww.xker.com()


  C:\WINDOWS\RUNDLL.EXE SETUPX.DLL,INSTALLHINFSECTION DEFAULTINSTALL 132 CLEAN.INF


  ECHOY |ERASE C:\WINDOWS\RECENT



  各位可将CLEAN.BAT 加入HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN中让电脑自动在启动时完成任务.