Windows Script Host是个很有意思的东西,利用它跟Windows系统内部的运作,可以把一些相对复杂的问题简单化,比如申请qq号码,完全可以转化成“建立IE进程-》发送模拟按键填写信息”这样一个过程。
什么是Windows Script Host?
Windows Script Host (WSH) is a Windows administration tool.
WSH creates an environment for hosting scripts. That is, when a script arrives at your computer, WSH plays the part of the host — it makes objects and services available for the script and provides a set of guidelines within which the script is executed. Among other things, Windows Script Host manages security and invokes the appropriate script engine.
WSH is language-independent for WSH-compliant scripting engines. It brings simple, powerful, and flexible scripting to the Windows platform, allowing you to run scripts from both the Windows desktop and the command prompt.
Windows Script Host is ideal for noninteractive scripting needs, such as logon scripting, administrative scripting, and machine automation.
MSDN:http://msdn.microsoft.com/en-us/library/9bbdkx3k(v=VS.85).aspx
下面就是一个小例子,将代码保存为a.vbs并执行,等到光标在输入验证码框时输入验证码,即可获得一个新的QQ号码。
1: Set a=WScript.CreateObject("WScript.shell")
2: a.run "http://newreg.qq.com/" '打开QQ号码申请页面
3: WScript.Sleep 4000 '延时10秒,等待页面载入
4: a.SendKeys "username_123" '这里填写昵称
5: a.SendKeys "{TAB}"
6: WScript.Sleep 200
7: a.SendKeys "{DOWN}"
8: a.SendKeys "{TAB}"
9: WScript.Sleep 200
10: a.SendKeys "{DOWN}"
11: a.SendKeys "{TAB}"
12: WScript.Sleep 200
13: a.SendKeys "{DOWN}"
14: WScript.Sleep 200
15: a.SendKeys "{TAB}"
16: WScript.Sleep 200
17: a.SendKeys "{TAB}"
18: WScript.Sleep 200
19: a.SendKeys "password123" '这里是密码
20: a.SendKeys "{TAB}"
21: WScript.Sleep 200
22: a.SendKeys "password123" '再次输入密码
23: WScript.Sleep 200
24: a.SendKeys "{TAB}"
25: WScript.Sleep 200
26: a.SendKeys "{TAB}"
27: WScript.Sleep 200
28: a.SendKeys "{TAB}"
29: WScript.Sleep 200
30: a.SendKeys "{TAB}"
31: WScript.Sleep 4000 '填写验证图片
32: a.SendKeys "{ENTER}"
33: WScript.Sleep 4000 '填写验证图片