主要是用WScript.Shell是讀寫Registry的值。
若發生「 Automation 伺服程式無法產生物件」的錯誤就要調整IE的安全性設定,將「起始不標示為安全的ActiveX控制項」設定為啟用或提示。

<script language="javascript"> // 列印 function fnPrint() { try { // 儲存原本頁首頁尾的設定,然後設定空白 var ret = saveAndClearSetting(); // 列印 window.print(); // 回存原本頁首頁尾的設定 if ( ret ) restoreSetting(); } catch (e) { alert("err="+e.description); } } var hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\"; var hkey_key_header = hkey_path+"header"; // 頁首 var hkey_key_footer = hkey_path+"footer"; // 頁尾 var hkey_key_margin_bottom = hkey_path+"margin_bottom"; // 邊界(下) var hkey_key_margin_left = hkey_path+"margin_left"; // 邊界(左) var hkey_key_margin_right = hkey_path+"margin_right"; // 邊界(右) var hkey_key_margin_top = hkey_path+"margin_top"; // 邊界(上) var old_header = "&w&b第 &p 頁,共 &P 頁"; var old_footer = "&u&b&d"; // 儲存原本頁首頁尾的設定,然後設定空白 function saveAndClearSetting() { try { var RegWsh = new ActiveXObject("WScript.Shell"); old_header = RegWsh.RegRead(hkey_key_header); old_footer = RegWsh.RegRead(hkey_key_footer); RegWsh.RegWrite(hkey_key_header,""); RegWsh.RegWrite(hkey_key_footer,""); return true; } catch (e) { if ( e.description.indexOf("伺服程式無法產生物件") != -1 ) { alert("請調整IE瀏覽器的安全性\n網際網路選項\安全性\自訂層級\n「起始不標示為安全的ActiveX控制項」設定為啟用或提示。"); } // if else { alert("ERR="+e.description); } // else } // catch return false; } // 回存原本頁首頁尾的設定 function restoreSetting() { try { var RegWsh = new ActiveXObject("WScript.Shell"); RegWsh.RegWrite(hkey_key_header,old_header); RegWsh.RegWrite(hkey_key_footer,old_footer); } catch (e) { if ( e.description.indexOf("伺服程式無法產生物件") != -1 ) { alert("請調整IE瀏覽器的安全性\n網際網路選項\安全性\自訂層級\n「起始不標示為安全的ActiveX控制項」設定為啟用或提示。"); } // if else { alert("ERR="+e.description); } // else } // catch } </script>
http://klcintw4.blogspot.com/2007/09/javascriptie.html