(推荐!) (不推荐)
原始檔(printIE.js):(灰色區域按兩下即可拷貝)// 由 IE 列印網頁 objMyIE = WScript.CreateObject("InternetExplorer.Application"); URL="http://neural.cs.nthu.edu.tw/jang"; //URL="http://www.google.com"; //URL="file://d:/users/jang/books/wsh/example/test.htm"; objMyIE.Navigate(URL); objMyIE.visible = true; while (objMyIE.Busy) WScript.Sleep(1000); WshShell=new ActiveXObject("WScript.Shell"); WshShell.SendKeys("%{f}"); WScript.Sleep(1000); WshShell.SendKeys("p"); WScript.Sleep(1000); WshShell.SendKeys("%{p}"); //objMyIE.document.parentWindow.Print(); // 有 bug! //objMyIE.Quit(); 我們也可以開啟記事本並寫入文字: 原始檔(sendKeys01.js):(灰色區域按兩下即可拷貝)// 使用 SendKeys 去開啟記事本並寫入文字、存檔 WshShell=new ActiveXObject("WScript.Shell"); WshShell.Run("notepad", 9); WScript.Sleep(500); // Give Notepad some time to load for (i=0; i<10; i++){ WshShell.SendKeys(i+". Hello World!"); WshShell.SendKeys("{ENTER}"); } WshShell.SendKeys("%{F}"); WshShell.SendKeys("s"); WshShell.SendKeys("test.txt"); WshShell.SendKeys("{TAB}{TAB}{ENTER}"); WshShell.SendKeys("y"); WshShell.SendKeys("%{F4}"); 若要開啟 IE 並設定我的最愛,可見下列範例: 原始檔(sendKeys02.js):(灰色區域按兩下即可拷貝)// 設定我的最愛(還有一些小問題!) WshShell=new ActiveXObject("WScript.Shell"); WshShell.Run("iexplore", 9); WScript.Sleep(1000); // Give Notepad some time to load WshShell.SendKeys("%t"); WshShell.SendKeys("o"); WScript.Quit(1); //WshShell.SendKeys("http://neural.cs.nthu.edu.tw/jang"); WshShell.SendKeys("http://www.cs.nthu.edu.tw"); WScript.Quit(1); for (i=0; i<13; i++) WshShell.SendKeys("{TAB}"); WScript.Quit(1); WshShell.SendKeys("{ENTER}");
// 由 IE 列印網頁 objMyIE = WScript.CreateObject("InternetExplorer.Application"); URL="http://neural.cs.nthu.edu.tw/jang"; //URL="http://www.google.com"; //URL="file://d:/users/jang/books/wsh/example/test.htm"; objMyIE.Navigate(URL); objMyIE.visible = true; while (objMyIE.Busy) WScript.Sleep(1000); WshShell=new ActiveXObject("WScript.Shell"); WshShell.SendKeys("%{f}"); WScript.Sleep(1000); WshShell.SendKeys("p"); WScript.Sleep(1000); WshShell.SendKeys("%{p}"); //objMyIE.document.parentWindow.Print(); // 有 bug! //objMyIE.Quit();
我們也可以開啟記事本並寫入文字:
// 使用 SendKeys 去開啟記事本並寫入文字、存檔 WshShell=new ActiveXObject("WScript.Shell"); WshShell.Run("notepad", 9); WScript.Sleep(500); // Give Notepad some time to load for (i=0; i<10; i++){ WshShell.SendKeys(i+". Hello World!"); WshShell.SendKeys("{ENTER}"); } WshShell.SendKeys("%{F}"); WshShell.SendKeys("s"); WshShell.SendKeys("test.txt"); WshShell.SendKeys("{TAB}{TAB}{ENTER}"); WshShell.SendKeys("y"); WshShell.SendKeys("%{F4}");
若要開啟 IE 並設定我的最愛,可見下列範例:
// 設定我的最愛(還有一些小問題!) WshShell=new ActiveXObject("WScript.Shell"); WshShell.Run("iexplore", 9); WScript.Sleep(1000); // Give Notepad some time to load WshShell.SendKeys("%t"); WshShell.SendKeys("o"); WScript.Quit(1); //WshShell.SendKeys("http://neural.cs.nthu.edu.tw/jang"); WshShell.SendKeys("http://www.cs.nthu.edu.tw"); WScript.Quit(1); for (i=0; i<13; i++) WshShell.SendKeys("{TAB}"); WScript.Quit(1); WshShell.SendKeys("{ENTER}");