2011-05-26 15:29 1830人阅读 评论(0) 收藏 举报

版权声明:本文为博主原创文章,未经博主允许不得转载。

什么是VBscript 呢?

VBscrīpt 的全称是:Microsoft Visual Basic scrīpt Editon.(微软公司可视化BASIC 脚本
版). VBS(VBscrīpt 的进一步简写)是基于Visual Basic 的脚本语言,其不编译成二进制文件, 而是直接由
宿主(host)解释源代码并执行, 简单点说就是你写的程序不需要编译成.exe, 而是直接给用户发送.vbs 的
源程序, 用户就能执行了.
SendKeys 方法
模拟键盘操作,将一个或多个按键指令发送到指定Windows 窗口来控制应用程序运行,
其使用格式为:object.SendKeys(string)
“object”:表示WshShell 对象
“string”:表示要发送的按键指令字符串,需要放在英文双引号中。
-----------------------------------
1.基本键
一般来说,要发送的按键指令都可以直接用该按键字符本身来表示,例如要发送字母“x”,使用
“WshShell.SendKeys "x"”即可。当然,也可直接发送多个按键指令,只需要将按键字符按顺序排列在一
起即可,例如,要发送按键“happy”,可以使用“ WshShell.SendKeys "happy" ”。
2.特殊功能键
对于需要与Shift、Ctrl、Alt 三个控制键组合的按键,SendKeys 使用特殊字符来表示:
Shift---------WshShell.SendKeys "+"
Ctrl---------WshShell.SendKeys "^"
Alt---------WshShell.SendKeys "%" (注意这样使用时,不用大括号括起这些特殊字符。)
由于“+”、“^”这些字符用来表示特殊的控制按键了,如何表示这些按键呢? 只要用大括号括住这
些字符即可。例如: 要发送加号“+”,可使用“WshShell.SendKeys "{+}"”
另外对于一些不会生成字符的控制功能按键,也同样需要使用大括号括起来按键的名称。
例如要发送回车键,需要用“ WshShell.SendKeys "{ENTER}" ”表示;
发送向下的方向键用“ Wshell.SendKeys "{DOWN}" ”表示。
Space---------WshShell.SendKeys " "
Enter---------WshShell.SendKeys "{ENTER}"
←---------WshShell.SendKeys "{RIGHT}"
↑---------WshShell.SendKeys "{UP}"
F1---------WshShell.SendKeys "{F1}"
 
 
 
按键代码
BACKSPACE {BACKSPACE}, {BS}, 或{BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or Delete {Delete} 或{DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}或~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or Insert {Insert} 或{INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
 
Tips:如果需要发送多个重复的单字母按键,不必重复输入该字母,SendKeys 允许使用简化格式进行描述,
使用格式为“{按键数字}”。例如要发送10 个字母“x”,则输入“WshShell.SendKeys "{x 10}"”即
可。
-----------------------------------
按下F5 刷新桌面
 
Dim WshShell,Path,i
Set WshShell = Wscrīpt.CreateObject("Wscrīpt.Shell")
WshShell.SendKeys "{F5}"
----------------------------------------------------
 
电脑的自动重启
set WshShell = CreateObject("Wscrīpt.Shell")
WshShell.SendKeys "^{ESC}u"
WshShell.SendKeys "R"
 
----------------------------------------------------
启动任务管理器
set WshShell = CreateObject("Wscrīpt.Shell")
WshShell.SendKeys "^+{ESC}"
----------------------------------------------------
QQ 消息连发
Dim WshShell
Set WshShell= Wscrīpt.createObject("Wscrīpt.Shell")
WshShell.AppActivate "bomb"
for i=1 to 60
Wscrīpt.Sleep 800
WshShell.SendKeys "What do you say"
WshShell.SendKeys i
WshShell.SendKeys "%s"
next
----------------------------------------------------
自动到百度搜索歌曲:white flag
Dim WshShell,Path,i
Set WshShell = Wscrīpt.CreateObject("Wscrīpt.Shell")
WshShell.Run("IEXPLORE.EXE")
Wscrīpt.Sleep 2000
WshShell.AppActivate "about:blank-Microsoft Internet Explorer"
WshShell.SendKeys "+{TAB}"
WshShell.SendKeys "http://mp3.baidu.com"
Wscrīpt.Sleep 800
WshShell.SendKeys "{ENTER}"
Wscrīpt.Sleep 3000
WshShell.SendKeys "white flag"
Wscrīpt.Sleep 800
WshShell.SendKeys "{ENTER}"
----------------------------------------------------
自动关机
Dim WshShell
Set WshShell=Wscrīpt.CreateObject("Wscrīpt.Shell")
Wscrīpt.Sleep 2000
WshShell.Run "shutdown -r -t 120"
wscrīpt.sleep 6000
WshShell.Run "shutdown -a"
----------------------------------------------------
在记事本中输入Happy Birthday!并保存为birth.txt
 
Dim WshShell
Set WshShell=Wscrīpt.CreateObject("Wscrīpt.Shell")
WshShell.Run "notepad"
 
Wscrīpt.Sleep 1500
WshShell.AppActivate "无标题- 记事本"
WshShell.SendKeys "H"
Wscrīpt.Sleep 500
WshShell.SendKeys "a"
Wscrīpt.Sleep 500
WshShell.SendKeys "p"
Wscrīpt.Sleep 500
WshShell.SendKeys "p"
Wscrīpt.Sleep 500
WshShell.SendKeys "y"
Wscrīpt.Sleep 500
WshShell.SendKeys " "
Wscrīpt.Sleep 500
WshShell.SendKeys "B"
Wscrīpt.Sleep 500
WshShell.SendKeys "i"
Wscrīpt.Sleep 500
WshShell.SendKeys "r"
Wscrīpt.Sleep 500
WshShell.SendKeys "t"
Wscrīpt.Sleep 500
WshShell.SendKeys "h"
Wscrīpt.Sleep 500
WshShell.SendKeys "d"
Wscrīpt.Sleep 500
WshShell.SendKeys "a"
Wscrīpt.Sleep 500
WshShell.SendKeys "y"
Wscrīpt.Sleep 500
WshShell.SendKeys "!"
Wscrīpt.Sleep 500
WshShell.SendKeys "%FS"
Wscrīpt.Sleep 500
WshShell.SendKeys "b"
Wscrīpt.Sleep 500
WshShell.SendKeys "i"
Wscrīpt.Sleep 500
WshShell.SendKeys "r"
Wscrīpt.Sleep 500
WshShell.SendKeys "t"
Wscrīpt.Sleep 500
WshShell.SendKeys "h"
Wscrīpt.Sleep 500
WshShell.SendKeys "%S"
Wscrīpt.Sleep 500
WshShell.SendKeys "%FX"
----------------------------------------------------
制作能自动定时存盘的记事本
 
第一部分:定义变量和对象
Dim WshShell, AutoSaveTime, TXTFileName
AutoSaveTime=300000
Set WshShell=Wscrīpt.CreateObject("Wscrīpt.Shell")
TXTFileName=InputBox("请输入你要创建的文件名(不能用中文和纯数字):")
 
第二部分:打开并激活记事本
WshShell.Run "notepad"
Wscrīpt.Sleep 200
WshShell.AppActivate "无标题- 记事本"
 
'第三部分:用输入的文件名存盘
WshShell.SendKeys "^s"
Wscrīpt.Sleep 300
WshShell.SendKeys TXTFileName
Wscrīpt.Sleep 300
WshShell.SendKeys "%s"
Wscrīpt.Sleep AutoSaveTime
 
'第四部分:自动定时存盘
While WshShell.AppActivate (TXTFileName)=True
WshShell.SendKeys "^s"
Wscrīpt.Sleep AutoSaveTime
Wend
Wscrīpt.Quit
----------------------------------------------------
DIM WSHSHELL
SET WSHSHELL=Wscrīpt.CreateOBJECT("Wscrīpt.SHELL")
'WSHSHELL.RUN " "
'Wscrīpt.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'Wscrīpt.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'Wscrīpt.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'Wscrīpt.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
'Wscrīpt.SLEEP 1000
WSHSHELL.SENDKEYS "{ENTER}"
 

vbs use的更多相关文章

  1. C#调用vbs脚本实现Windows版Siri

    最近新加入,把自己一些有意思的小东西分享给大家,我是一个学生,代码写得少,哪里不规范,希望大家见谅. 这事我封装好的一个类,可以直接实例化对象之后,调用"对象.Talk()"方法, ...

  2. 在WinCC中通过VBS操作SQL Server2005

    在项目中需要在一定条件满足时,保存一些数据到数据库中,并可根据条件查询.考虑到WinCC6.2以后采用的就是SQL Server2005数据库,所以直接利用该数据库即可,通过SQL Server Ma ...

  3. 使用vbs脚本进行批量编码转换

    使用vbs脚本进行批量编码转换 最近需要使用SourceInsight查看分析在Linux系统下开发的项目代码,我们知道Linux系统中文本文件默认编码格式是UTF-8,而Windows中文系统中的默 ...

  4. vbs让电脑发音说话

    Dim vbs1 'set vbs1 = WScript.CreateObject("WScript.Shell") set vbs1 = WScript.CreateObject ...

  5. WSF脚本详解:组合JS和VBS代码

    1.概述 Windows Script Host除了提供一个对象模型之外,还提供了一种脚本框架,这就是WSF脚本.通过WSF约定的标记元素,可以将多种脚本语言写的代码块组合起来,完成任务.除此之外,还 ...

  6. HTA全解析:给VBS和JS一个强大的交互界面

    1.概述 HTA全称Html Application,在Windows中由mshta.exe加载执行,是一种本地程序.可使用html元素来构建界面,用JS或VBS来构建执行逻辑,从而强化Windows ...

  7. vbs 中文字符串

    vbs 字符串包含中文字符,文件以UTF-8无BOM格式保存,就会出现“编译器错误: 未结束的字符串常量”错误,改以ANSI保存就没有这个问题

  8. 使用bat/vbs/ahk对Windows下进行自动化操作

    回想90年代,我们在DOS下使用各种命令链对操作进行简化和自动化,如DOS 5.0添加的DosKey,利用管道和重定向对多组命令进行链式操作.后来使用了Ubuntu和其它Linux发型版后,bash下 ...

  9. vbs 的二个解释程序区别与切换及与BAT互调用。

    WScript.exe : 窗口中运行CScript.exe :命令行中运行 用法:<CScript|WScript> scriptname.extension [option...] [ ...

  10. 用VBS实现公司自动打卡

    公司每天要求早晚打卡,方式是登录某一个页面,然后点击上面的圈圈,如下图: 每天都要打开书签,登录这个页面,然后打卡...这么重复性的工作,怎么能是程序员天天干的事情呢(其实是我太懒了),那么就尝试让程 ...

随机推荐

  1. Laravel5.1学习笔记15 数据库1 数据库使用入门

    简介 运行原生SQL查询  监听查询事件 数据库事务 使用多数据库连接 简介 Laravel makes connecting with databases and running queries e ...

  2. python 之 sqlite3

    # -*- coding: utf-8 -*- ''' 创建数据库日志,三列为时间 身份证号和备注名''' import os import sys import sqlite3 import dat ...

  3. CSS动画:旋转卡片效果

    <!DOCTYPE html> <html> <head> <title>demo</title> </head> <bo ...

  4. Ubuntu 关闭guest用户

    Ubuntu 关闭guest用户 ca0gu0@ub:~$ cat /etc/lightdm/lightdm.conf [SeatDefaults]autologin-user=falseallow- ...

  5. php银联支付

    简介 PHP银联支付 流程 1.注册 银联 - 技术开发平台和商户服务平台 https://open.unionpay.com 注意:注册时建议使用IE浏览器,之前注册时插件老是用不了,使用IE10以 ...

  6. 【上海站】EOLINKER 用户培训之旅,等你来共建API新连接

    从今年3月4日起,EOLINKER AMS 团队将再次开启全国用户培训之旅.本次全国培训之旅依旧将覆盖北上广深等国内主要城市,重点提供两种服务内容,一是 对 EOLINKER 产品的交流,包括 API ...

  7. Xcode 插件因为UUID原因不能使用解决办法

    Xcode 经常因为一些原因不能使用,需要重新在  ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins目录下对每一个插件包下的p ...

  8. 关于javascript原型链的记录

    构造函数拥有名为prototype属性,每个对象都拥有__proto__属性,而且每个对象的__proto__属性指向自身构造函数prototype. **当调用某种方法或属性时,首先会在自身调用或查 ...

  9. Shell 脚本编程 基本语法:

    Shell 脚本编程语法: 注: 文章来源 http://www.cnblogs.com/yunquan/p/6821850.html 视频来源:https://www.bilibili.com/vi ...

  10. 3.filter原理(bitset机制与caching机制)

    主要知识点: 一次filter执行顺序 filter和query的特点     一.一次filter执行顺序     1.在倒排索引中查找搜索串,获取document list 以一下date数据来举 ...