此技術使用 JScript 搭配 WSH (Windows Script Host),透過 InternetExplorer.Application COM 物件自動化 IE 瀏覽器,實現網頁表單自動填寫與提交。注意:這不是 C# 程式碼,而是獨立的 .js 腳本。
var ie = WScript.CreateObject("InternetExplorer.Application");
var args = WScript.Arguments;
var targetUrl = "https://www.google.com/";
if (args.length > 0)
targetUrl += args(0);
ie.Navigate("https://www.google.com/accounts/Login?continue=" + targetUrl);
WaitForIE(ie);
var doc = ie.Document;
doc.forms[0].Email.value = "your_account@gmail.com";
doc.forms[0].Passwd.value = "你的密碼";
// 處理「保持登入」核取方塊可能不存在的情況
if (doc.forms[0].PersistentCookie != null)
doc.forms[0].PersistentCookie.checked = false;
doc.forms[0].submit();
WaitForIE(ie);
ie.Visible = true; // 最後才顯示視窗
function WaitForIE(ieObj)
{
while (ieObj.Busy)
WScript.Sleep(100);
}
@echo off
wscript "%windir%\system32\googleLogin.js" %1 %2 %3 %4 %5 %6 %7 %8 %9
googleLogin.js 與 google.bat 放入 %windir%\system32\(或任何在 PATH 環境變數的目錄)google mail → 直接登入 Gmailgoogle notebook(筆記本)、google bookmarks(書籤)等google → 以登入身分進入 Google 首頁| 方法 | 說明 | 安全性 |
|---|---|---|
| 明文密碼 | 腳本中直接寫死密碼 | ❌ 極低,任何人可讀取 |
screnc.exe 加密 | 產生 .jse 加密腳本 | ⚠️ 低,scrdec 可解密 |
| 環境變數讀取 | WScript.CreateObject("WScript.Shell").Environment("USER")("GMAIL_PWD") | ✅ 中,密碼不在檔案中 |
| Windows Credential Manager | 呼叫 CredRead API 讀取儲存的憑證 | ✅ 高,系統級加密儲存 |
| 改用 C# + Selenium/WebDriver | 現代化瀏覽器自動化框架 | ✅ 最高,支援無頭模式、多瀏覽器 |
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
var options = new ChromeOptions();
options.AddArgument("--headless"); // 無頭模式
using (var driver = new ChromeDriver(options))
{
driver.Navigate().GoToUrl("https://accounts.google.com/signin");
driver.FindElement(By.Id("identifierId")).SendKeys("your@gmail.com");
driver.FindElement(By.Id("identifierNext")).Click();
// 等待密碼欄位出現...
driver.FindElement(By.Name("password")).SendKeys("password");
driver.FindElement(By.Id("passwordNext")).Click();
// 登入完成
}