VBS中SendKeys的基本應(yīng)用
更新時間:2006年11月06日 00:00:00 作者:
ps:不知道有人還記得這個攻擊qq群的代碼?就是利用這個所寫的!
SendKeys
模擬鍵盤操作,將一個或多個按鍵指令發(fā)送到指定Windows窗口來控制應(yīng)用程序運行,
其使用格式為:object.SendKeys string
“object”:表示W(wǎng)shShell對象
“string”:表示要發(fā)送的按鍵指令字符串,需要放在英文雙引號中。
1.基本鍵
一般來說,要發(fā)送的按鍵指令都可以直接用該按鍵字符本身來表示,例如要發(fā)送字母“x”,使用“WshShell.SendKeys "x"”即可。當(dāng)然,也可直接發(fā)送多個按鍵指令,只需要將按鍵字符按順序排列在一起即可,例如,要發(fā)送按鍵“happy”,可以使用“WshShell.SendKeys "happy"”。
2.特殊功能鍵
對于需要與Shift、Ctrl、Alt三個控制鍵組合的按鍵,SendKeys使用特殊字符來表示:
Shift---------WshShell.SendKeys "+"
Ctrl---------WshShell.SendKeys "^"
Alt---------WshShell.SendKeys "%"
由于“+”、“^”這些字符用來表示特殊的控制按鍵了,如何表示這些按鍵呢?
只要用大括號括住這些字符即可。例如:
要發(fā)送加號“+”,可使用“WshShell.SendKeys "{+}"”
另外對于一些不會生成字符的控制功能按鍵,也同樣需要使用大括號括起來按鍵的名稱,例如要發(fā)送回車鍵,需要用“WshShell.SendKeys "{ENTER}"”表示,發(fā)送向下的方向鍵用“WshShell.SendKeys "{DOWN}"”表示。
Space---------WshShell.SendKeys " "
Enter---------WshShell.SendKeys "{ENTER}"
←---------WshShell.SendKeys "{RIGHT}"
↑---------WshShell.SendKeys "{UP}"
F1---------WshShell.SendKeys "{F1}"
Tips:如果需要發(fā)送多個重復(fù)的單字母按鍵,不必重復(fù)輸入該字母,SendKeys允許使用簡化格式進(jìn)行描述,使用格式為“{按鍵 數(shù)字}”。例如要發(fā)送10個字母“x”,則輸入“WshShell.SendKeys "{x 10}"”即可。
實例:
----------------------------------------------------
按下F5刷新桌面
Dim WshShell,Path,i
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{F5}"
----------------------------------------------------
電腦的自動重啟
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^{ESC}u"
WshShell.SendKeys "R"
----------------------------------------------------
啟動任務(wù)管理器
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^+{ESC}"
----------------------------------------------------
QQ消息群發(fā)
Dim WshShell
Set WshShell= WScript.createObject("WScript.Shell")
WshShell.AppActivate "bomb"
for i=1 to 60
WScript.Sleep 800
WshShell.SendKeys "Number0"
WshShell.SendKeys i
WshShell.SendKeys "%s"
next
----------------------------------------------------
自動到百度搜索歌曲:white flag
Dim WshShell,Path,i
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("IEXPLORE.EXE")
WScript.Sleep 2000
WshShell.AppActivate "about:blank-Microsoft Internet Explorer"
WshShell.SendKeys "+{TAB}"
WshShell.SendKeys "http://mp3.baidu.com"
WScript.Sleep 800
WshShell.SendKeys "{ENTER}"
WScript.Sleep 3000
WshShell.SendKeys "white flag"
WScript.Sleep 800
WshShell.SendKeys "{ENTER}"
----------------------------------------------------
在記事本中輸入Happy Birthday!并保存為birth.txt
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
WScript.Sleep 1500
WshShell.AppActivate "無標(biāo)題 - 記事本"
WshShell.SendKeys "H"
WScript.Sleep 500
WshShell.SendKeys "a"
WScript.Sleep 500
WshShell.SendKeys "p"
WScript.Sleep 500
WshShell.SendKeys "p"
WScript.Sleep 500
WshShell.SendKeys "y"
WScript.Sleep 500
WshShell.SendKeys " "
WScript.Sleep 500
WshShell.SendKeys "B"
WScript.Sleep 500
WshShell.SendKeys "i"
WScript.Sleep 500
WshShell.SendKeys "r"
WScript.Sleep 500
WshShell.SendKeys "t"
WScript.Sleep 500
WshShell.SendKeys "h"
WScript.Sleep 500
WshShell.SendKeys "d"
WScript.Sleep 500
WshShell.SendKeys "a"
WScript.Sleep 500
WshShell.SendKeys "y"
WScript.Sleep 500
WshShell.SendKeys "!"
WScript.Sleep 500
WshShell.SendKeys "%FS"
WScript.Sleep 500
WshShell.SendKeys "b"
WScript.Sleep 500
WshShell.SendKeys "i"
WScript.Sleep 500
WshShell.SendKeys "r"
WScript.Sleep 500
WshShell.SendKeys "t"
WScript.Sleep 500
WshShell.SendKeys "h"
WScript.Sleep 500
WshShell.SendKeys "%S"
WScript.Sleep 500
WshShell.SendKeys "%FX"
----------------------------------------------------
制作能自動定時存盤的記事本
'第一部分:定義變量和對象
Dim WshShell, AutoSaveTime, TXTFileName
AutoSaveTime=300000
Set WshShell=WScript.CreateObject("WScript.Shell")
TXTFileName=InputBox("請輸入你要創(chuàng)建的文件名(不能用中文和純數(shù)字):")
'第二部分:打開并激活記事本
WshShell.Run "notepad"
WScript.Sleep 200
WshShell.AppActivate "無標(biāo)題 - 記事本"
'第三部分:用輸入的文件名存盤
WshShell.SendKeys "^s"
WScript.Sleep 300
WshShell.SendKeys TXTFileName
WScript.Sleep 300
WshShell.SendKeys "%s"
WScript.Sleep AutoSaveTime
'第四部分:自動定時存盤
While WshShell.AppActivate (TXTFileName)=True
WshShell.SendKeys "^s"
WScript.Sleep AutoSaveTime
Wend
WScript.Quit
----------------------------------------------------
死機(jī)的,嘿嘿!
DIM WSHSHELL
SET WSHSHELL=WSCRIPT.CREATEOBJECT("WSCRIPT.SHELL")
'WSHSHELL.RUN " "
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
----------------------------------------------------
定時關(guān)機(jī)的
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WScript.Sleep 2000
WshShell.Run "shutdown -r -t 120"
wscript.sleep 6000
WshShell.Run "shutdown -a
SendKeys
模擬鍵盤操作,將一個或多個按鍵指令發(fā)送到指定Windows窗口來控制應(yīng)用程序運行,
其使用格式為:object.SendKeys string
“object”:表示W(wǎng)shShell對象
“string”:表示要發(fā)送的按鍵指令字符串,需要放在英文雙引號中。
1.基本鍵
一般來說,要發(fā)送的按鍵指令都可以直接用該按鍵字符本身來表示,例如要發(fā)送字母“x”,使用“WshShell.SendKeys "x"”即可。當(dāng)然,也可直接發(fā)送多個按鍵指令,只需要將按鍵字符按順序排列在一起即可,例如,要發(fā)送按鍵“happy”,可以使用“WshShell.SendKeys "happy"”。
2.特殊功能鍵
對于需要與Shift、Ctrl、Alt三個控制鍵組合的按鍵,SendKeys使用特殊字符來表示:
Shift---------WshShell.SendKeys "+"
Ctrl---------WshShell.SendKeys "^"
Alt---------WshShell.SendKeys "%"
由于“+”、“^”這些字符用來表示特殊的控制按鍵了,如何表示這些按鍵呢?
只要用大括號括住這些字符即可。例如:
要發(fā)送加號“+”,可使用“WshShell.SendKeys "{+}"”
另外對于一些不會生成字符的控制功能按鍵,也同樣需要使用大括號括起來按鍵的名稱,例如要發(fā)送回車鍵,需要用“WshShell.SendKeys "{ENTER}"”表示,發(fā)送向下的方向鍵用“WshShell.SendKeys "{DOWN}"”表示。
Space---------WshShell.SendKeys " "
Enter---------WshShell.SendKeys "{ENTER}"
←---------WshShell.SendKeys "{RIGHT}"
↑---------WshShell.SendKeys "{UP}"
F1---------WshShell.SendKeys "{F1}"
Tips:如果需要發(fā)送多個重復(fù)的單字母按鍵,不必重復(fù)輸入該字母,SendKeys允許使用簡化格式進(jìn)行描述,使用格式為“{按鍵 數(shù)字}”。例如要發(fā)送10個字母“x”,則輸入“WshShell.SendKeys "{x 10}"”即可。
實例:
----------------------------------------------------
按下F5刷新桌面
Dim WshShell,Path,i
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "{F5}"
----------------------------------------------------
電腦的自動重啟
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^{ESC}u"
WshShell.SendKeys "R"
----------------------------------------------------
啟動任務(wù)管理器
set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys "^+{ESC}"
----------------------------------------------------
QQ消息群發(fā)
Dim WshShell
Set WshShell= WScript.createObject("WScript.Shell")
WshShell.AppActivate "bomb"
for i=1 to 60
WScript.Sleep 800
WshShell.SendKeys "Number0"
WshShell.SendKeys i
WshShell.SendKeys "%s"
next
----------------------------------------------------
自動到百度搜索歌曲:white flag
Dim WshShell,Path,i
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("IEXPLORE.EXE")
WScript.Sleep 2000
WshShell.AppActivate "about:blank-Microsoft Internet Explorer"
WshShell.SendKeys "+{TAB}"
WshShell.SendKeys "http://mp3.baidu.com"
WScript.Sleep 800
WshShell.SendKeys "{ENTER}"
WScript.Sleep 3000
WshShell.SendKeys "white flag"
WScript.Sleep 800
WshShell.SendKeys "{ENTER}"
----------------------------------------------------
在記事本中輸入Happy Birthday!并保存為birth.txt
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad"
WScript.Sleep 1500
WshShell.AppActivate "無標(biāo)題 - 記事本"
WshShell.SendKeys "H"
WScript.Sleep 500
WshShell.SendKeys "a"
WScript.Sleep 500
WshShell.SendKeys "p"
WScript.Sleep 500
WshShell.SendKeys "p"
WScript.Sleep 500
WshShell.SendKeys "y"
WScript.Sleep 500
WshShell.SendKeys " "
WScript.Sleep 500
WshShell.SendKeys "B"
WScript.Sleep 500
WshShell.SendKeys "i"
WScript.Sleep 500
WshShell.SendKeys "r"
WScript.Sleep 500
WshShell.SendKeys "t"
WScript.Sleep 500
WshShell.SendKeys "h"
WScript.Sleep 500
WshShell.SendKeys "d"
WScript.Sleep 500
WshShell.SendKeys "a"
WScript.Sleep 500
WshShell.SendKeys "y"
WScript.Sleep 500
WshShell.SendKeys "!"
WScript.Sleep 500
WshShell.SendKeys "%FS"
WScript.Sleep 500
WshShell.SendKeys "b"
WScript.Sleep 500
WshShell.SendKeys "i"
WScript.Sleep 500
WshShell.SendKeys "r"
WScript.Sleep 500
WshShell.SendKeys "t"
WScript.Sleep 500
WshShell.SendKeys "h"
WScript.Sleep 500
WshShell.SendKeys "%S"
WScript.Sleep 500
WshShell.SendKeys "%FX"
----------------------------------------------------
制作能自動定時存盤的記事本
'第一部分:定義變量和對象
Dim WshShell, AutoSaveTime, TXTFileName
AutoSaveTime=300000
Set WshShell=WScript.CreateObject("WScript.Shell")
TXTFileName=InputBox("請輸入你要創(chuàng)建的文件名(不能用中文和純數(shù)字):")
'第二部分:打開并激活記事本
WshShell.Run "notepad"
WScript.Sleep 200
WshShell.AppActivate "無標(biāo)題 - 記事本"
'第三部分:用輸入的文件名存盤
WshShell.SendKeys "^s"
WScript.Sleep 300
WshShell.SendKeys TXTFileName
WScript.Sleep 300
WshShell.SendKeys "%s"
WScript.Sleep AutoSaveTime
'第四部分:自動定時存盤
While WshShell.AppActivate (TXTFileName)=True
WshShell.SendKeys "^s"
WScript.Sleep AutoSaveTime
Wend
WScript.Quit
----------------------------------------------------
死機(jī)的,嘿嘿!
DIM WSHSHELL
SET WSHSHELL=WSCRIPT.CREATEOBJECT("WSCRIPT.SHELL")
'WSHSHELL.RUN " "
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'WSCRIPT.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
----------------------------------------------------
定時關(guān)機(jī)的
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WScript.Sleep 2000
WshShell.Run "shutdown -r -t 120"
wscript.sleep 6000
WshShell.Run "shutdown -a
相關(guān)文章
getSQLinfo.vbs 獲得SQL數(shù)據(jù)/日志空間使用情況的腳本
這個腳本可以獲取SQL數(shù)據(jù)/日志的空間使用情況方便及時了解sql使用空間情況2008-07-07
可以從一臺遠(yuǎn)程服務(wù)器運行 SP2 安裝程序Install.vbs
可以從一臺遠(yuǎn)程服務(wù)器運行 SP2 安裝程序Install.vbs...2007-04-04
使用 Iisftpdr.vbs 列出FTP虛擬目錄(支持遠(yuǎn)程與本地)
這篇文章主要介紹了如何通過 iisftpdr.vbs 列出本地或遠(yuǎn)程計算機(jī)上的 FTP 虛擬目錄的方法,需要的朋友可以參考下2014-07-07

