首頁 > web前端 > js教程 > 主體

js如何修改登錄檔

王林
發布: 2020-04-05 09:19:19
轉載
2298 人瀏覽過

js如何修改登錄檔

本文主要透過WshShell 物件的相關方法實作。

WshShell物件是WSH(WSH是Windows ing Host的縮寫,內嵌於Windows作業系統中的腳本語言工作環境)的內建對象,主要負責程式的本機運作、處理登錄、建立快捷方式、取得系統資料夾資訊及處理環境變數等工作。 

WshShell 物件的相關方法如表11.1所示。

js如何修改登錄檔

本實例中主要應用了 RegWrite方法,以下將對此方法進行詳細介紹。

RegWrite方法用於在登錄中設定指定的鍵或值,其語法格式如下:

WshShell.RegWrite strName, anyValue, [strType]
登入後複製

參數說明:

l     strName:用於指定登錄的鍵或值,若strName以一個反斜線(在中為//) 結束,則此方法設定鍵,否則設定值。 strName 參數必須以根鍵名稱「HKEY_CURRENT_USER」、 「HKEY_LOCAL_MACHINE」、「HKEY_CLASSES_ROOT」、「HKEY_USERS」或 「HKEY_CURRENT_CONFIG」開頭。

l     AnyValue:用於指定登錄機碼的鍵或值的值。當strType為REG_SZ或REG_EXPAND_SZ時,RegWrite方法會自動將 anyValue轉換為字串。若strType為REG_DWORD,則anyValue被轉換為整數。若strType為REG_BINARY,則 anyValue必須是一個整數。

l     StrType:用於指定登錄機碼的鍵或值的資料類型。 RegWrite方法支援的資料類型為REG_SZ、REG_EXPAND_SZ、 REG_DWORD和REG_BINARY。其他的資料型別被當作strType傳遞,RegWrite 傳回 E_INVALIDARG。

實作過程:

(1)寫自訂 函數PageSetup_del()和PageSetup_set(),用於實作清空頁首頁尾和恢復頁首頁尾的功能。具體程式碼如下:

< 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的標籤,呼叫WebBrowser控制項,程式碼如下:

< id="WebBrowser" classid="ClSID:8856F961-340A-11D0-A96B-00C04Fd705A2" width="0" height="0">

</ >
登入後複製

(3)建立「清空頁首頁尾」和「恢復頁首頁腳」的超級鏈接,並呼叫自訂函數PageSetup_del()和PageSetup_set()實現對應功能。程式碼如下:

<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)建立相關的列印超級鏈接,並呼叫WebBrowser控件的相應參數實現列印預覽、列印等功能。程式碼如下:

<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>
登入後複製

相關教學推薦:js教學

#

以上是js如何修改登錄檔的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:jb51.net
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!