詳解JavaScript修改注冊表的方法
本實例主要通過WshShell 對象的相關方法實現(xiàn)。WshShell對象是WSH(WSH是Windows ing Host的縮寫,內(nèi)嵌于Windows操作系統(tǒng)中的腳本語言工作環(huán)境)的內(nèi)建對象,主要負責程序的本地運行、處理注冊表、創(chuàng)建快捷方式、獲取系統(tǒng)文件夾信息及處理環(huán)境變量等工作。 WshShell 對象的相關方法如表11.1所示。
本實例中主要應用了 RegWrite方法,下面將對該方法進行詳細介紹。
RegWrite方法用于在注冊表中設置指定的鍵或值,其語法格式如下:
WshShell.RegWrite strName, anyValue, [strType]
參數(shù)說明
l strName:用于指定注冊表的鍵或值,若strName以一個反斜杠 (在 中為//) 結(jié)束,則該方法設置鍵,否則設置值。strName 參數(shù)必須以根鍵名“HKEY_CURRENT_USER”、 “HKEY_LOCAL_MACHINE”、“HKEY_CLASSES_ROOT”、“HKEY_USERS”或 “HKEY_CURRENT_CONFIG”開頭。
l AnyValue:用于指定注冊表的鍵或值的值。當strType為REG_SZ或REG_EXPAND_SZ時,RegWrite方法自動將 anyValue轉(zhuǎn)換為字符串。若strType為REG_DWORD,則anyValue被轉(zhuǎn)換為整數(shù)。若strType為REG_BINARY,則 anyValue必須是一個整數(shù)。
l StrType:用于指定注冊表的鍵或值的數(shù)據(jù)類型。RegWrite方法支持的數(shù)據(jù)類型為REG_SZ、REG_EXPAND_SZ、 REG_DWORD和REG_BINARY。其他的數(shù)據(jù)類型被作為strType傳遞,RegWrite 返回 E_INVALIDARG。
實現(xiàn)過程
(1)編寫自定義 函數(shù)PageSetup_del()和PageSetup_set(),用于實現(xiàn)清空頁眉頁腳和恢復頁眉頁腳的功能。具體代碼如下:
< language=" "> var HKEY_RootPath="HKEY_CURRENT_USER//Software//Microsoft//Internet Explorer//PageSetup//"; function PageSetup_del() { //清空頁眉頁腳 try { var WSc=new ActiveX ("W .Shell"); HKEY_Key="header"; WSc.RegWrite(HKEY_RootPath+HKEY_Key,""); HKEY_Key="footer"; WSc.RegWrite(HKEY_RootPath+HKEY_Key,""); }catch(e){} } function PageSetup_set() { //恢復頁眉頁腳 try{ var WSc=new ActiveX ("W .Shell"); HKEY_Key="header"; WSc.RegWrite(HKEY_RootPath+HKEY_Key,"&w&b頁碼,&p/&P"); HKEY_Key="footer"; WSc.RegWrite(HKEY_RootPath+HKEY_Key,"&u&b&d"); }catch(e){} } </ >
(2)建立HTML的 標簽,調(diào)用WebBrowser控件,代碼如下:
< id="WebBrowser" classid="ClSID:8856F961-340A-11D0-A96B-00C04Fd705A2" width="0" height="0"> </ >
(3)創(chuàng)建“清空頁眉頁腳”和“恢復頁眉頁腳”的超級鏈接,并調(diào)用自定義函數(shù)PageSetup_del()和PageSetup_set()實現(xiàn)相應功能。代碼如下:
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="PageSetup_del()">清空頁眉頁腳</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="PageSetup_set()"> 恢復頁眉頁腳 </a>
(4)建立相關的打印超級鏈接,并調(diào)用WebBrowser控件的相應參數(shù)實現(xiàn)打印預覽、打印等功能。代碼如下:
<a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(7,1)">打印預覽</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(6,1)">打印</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(6,6)">直接打印</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" ="document.all.WebBrowser.Execwb(8,1)">頁面設置</a>
總結(jié)
以上所述是小編給大家介紹的JavaScript修改注冊表的方法,希望對大家有所幫助!
上一篇:JS實現(xiàn)音樂導航特效
欄 目:JavaScript
本文標題:詳解JavaScript修改注冊表的方法
本文地址:http://mengdiqiu.com.cn/a1/JavaScript/9309.html
您可能感興趣的文章
- 04-02javascript潛力,javascript強大嗎
- 04-02javascript點線,點線的代碼
- 04-02javascript移出,js 移入移出
- 04-02javascript替換字符串,js字符串的替換
- 04-02包含javascript舍的詞條
- 04-02javascript匿名,js匿名方法
- 04-02javascript并行,深入理解并行編程 豆瓣
- 04-02javascript警報,JavaScript警告
- 04-02javascript前身,javascript的前身
- 04-02javascript遮蓋,JavaScript遮蓋PC端頁面


閱讀排行
本欄相關
- 04-02javascript點線,點線的代碼
- 04-02javascript潛力,javascript強大嗎
- 04-02javascript替換字符串,js字符串的替換
- 04-02javascript移出,js 移入移出
- 04-02包含javascript舍的詞條
- 04-02javascript并行,深入理解并行編程 豆瓣
- 04-02javascript匿名,js匿名方法
- 04-02javascript警報,JavaScript警告
- 04-02javascript遮蓋,JavaScript遮蓋PC端頁面
- 04-02javascript前身,javascript的前身
隨機閱讀
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 01-10delphi制作wav文件的方法
- 04-02jquery與jsp,用jquery
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-10C#中split用法實例總結(jié)
- 01-11ajax實現(xiàn)頁面的局部加載