name=inputbox(\"对话框内容\标题\") msgbox name,,\"标题\" name=\"2222222\" msgbox name,,\"\"
Cbool函数将变量转化成布尔值 Cbyte函数将变量转换成整数0-255 Ccur函数、Cdbl、Csing均转化为浮点 Cdate日期
Cint、Clong整数 ************** 数组: 0开始
dimarrray (9)代表0-8 array(4)代表第五个
redim来改变数组的个数、维数
改变数组的大小时会破坏数组的数据应用preserve来保护数据: redim preser array(个数,维数) ^乘方,mod取模,<>不等
Is 来比较对象,对象为同一类型则为真 ********************** 1、
If 条件 then 语句; ……. Endif
Else 也可以用 2、
For i=1 to 10 语句 Next
对数组内的每个都编辑的方法: For each I in 要查看的对象或数组 语句 Next
可以用exist for来退出循环 Do while 条件 循环体 Loop
Do until 条件 循环体 Loop
While 条件 循环体 Wend
********************************
过程:
函数、子程序
Function 函数名称(参数列表) 函数代码
函数名称=某值 ‘用来返回值
若直接用call调用函数,则返回值自动取消 ************************************** CreatObject可以访问windows安装的com对象 Wsh包括的对象:
1、 Scripting.FileSystemObject 提供一整套的文件系统操作函数 2、 Scripting.Dictionary 用来返回存放键值对的字典对象
3、 Wscript.shell 提供一套读取系统信息的函数,如读写注册表、查找指定文件的路径、读
取dos环境变量,读取连接中的设置 4、 Wscript.Network网络连接 Scripting存放在SCRRUN.DLL Wscript 存放在WSHOM.ocx 例子: 1、
Set objshell=CreateObject(\"Wscript.Shell\") Objshell.run \"notepad\"
打开了一个记事本
objshell被set成了一个对象,调用里面的run calc是计算器的 winword是word 等等
当软件路径有空格时,应如下:
Objshell.run \"\"\"E:\\Program Files\\Tencent\\QQ\\Bin\\QQ.exe\"\"\" 三个”
启动多个程序时:
Set objshell=CreateObject(\"Wscript.Shell\") Objshell.run \"notepad\" Objshell.run \"calc\" 则两个同时启动 若先后启动则:
Set objshell=CreateObject(\"Wscript.Shell\") Objshell.run \"notepad\Objshell.run \"calc\"
则关闭txt后才启动计算器
*.run参数三个:路径、窗口形式(0后台,1正常,2最小化,3最大化……)、true表示程序退出后脚本再继续进行
2、
注册表略
*******************************
文件系统进行访问管理的对象FSO:FileSystemObject 包括:
Drive对象 包含存储设备的信息
Drives集合 提供物理和逻辑驱动的列表 File对象 检查处理文件
Files集合 提供一个文件夹中的文件列表 Folder对象 提供文件夹中的子文件夹列表 Textstream对象 读写文本文件
FSO常见方法:
BuildPath:把文件路径信息添加到现有的文件路径上 CopyFile:复制文件
CopyFolder:复制文件夹 CreatFolder
CreatTextFile:创建文本并返回一个textstream对象 DeleteFile DeleteFolder
DriveExists:确定驱动器是否存在 FileExists:文件是否存在 FolderExists
GetAbsolutePathName返回文件或文件夹的路径 GetDrive:返回一个drive对象
GetDriveName返回一个驱动器的名字 GetExtensionName返回扩展名 GetFile返回一个file对象
GetFileName返回文件夹中文件名称 GetFolde:返回文件夹对象
GetParentFolderName返回父文件夹
GetTempName返回一个可以被createtextfile使用的文件夹名称 MoveFile移动文件 MoveFolder
OpenTextFile打开一个存在的文件并返回一个TextStream对象
FSO使用: Fso 模型建立
Set fs=wscript.createobject(“scripting.filesystemobject”) Fso模型释放 Set fs=nothing
使用文件夹 Dim fs,s
Set fs=wscript.createobject(\"scripting.filesystemobject\") If(fs. FolderExists(\"c:\emp\")) Then S=\"cun zai\" Else
S=\"bu cun zai\"
Set foldr=fs.createfolder(\"c:\emp\") End if
msgbox S,,\"\"
删除文件夹
Set fs=wscript.createobject(\"scripting.filesystemobject\") Fs.deletefolder(“---路径—“) 拷贝
Fs.copyfolder “源路径c:\\data“ “目的路径d:\\data”
若c:\\data与d:\\data同时存在会 出错,此时应强制覆盖: Fs.copyfolder “源路径c:\\data“ “目的路径d:\\data”,true 移动:
Fs.movefolder “c:\\data“ “d:\\data” 用folder属性删除文件夹:
Set fs=wscript.createobject(\"scripting.filesystemobject\") Set f=fs.getfolder(“c:\\data”) f.delete
特殊文件夹操作略
*************************** Sendkeys模拟键盘输入 Object.sendkeys string Object为Wshshell,例:
Set objshell=CreateObject(\"Wscript.Shell\") Objshell.run \"notepad\" Wscript.sleep 2000
Set Wshshell=Wscript.createObject(\"Wscript.shell\") Wshshell.sendkeys \"cfan\" 打开记事本两秒后输入cfan 组合键: Shift对应+ Ctrl对应^ Alt对应% Ctrl+E则为:
Wshshell.sendkeys \"^e\" Ctrl+E+C则为:
Wshshell.sendkeys \"^(ce)\"
注意与Wshshell.sendkeys \"^ce\"的区别……自己想
+号对应”{+}
Enter对应”{ENTER}
发送十个字母x则为:Wshshell.sendkeys \"{x 10}”
Wshshell.sendkeys \"^{esc}u”意思是:ctrl+esc打开开始菜单,然后按U键打开关机选项 Set objshell=CreateObject(\"Wscript.Shell\") Objshell.run \"notepad\" Wscript.sleep 2000
Set Wshshell=Wscript.createObject(\"Wscript.shell\") Wshshell.sendkeys \"hello hahah\" Wshshell.sendkeys \"{enter}\" Wshshell.sendkeys \"hahah hello\" Wshshell.sendkeys \"%{f4}\" Wshshell.sendkeys \"{enter}\" Wscript.sleep 2000
Wshshell.sendkeys \"e:\\my.txt\"
Wshshell.sendkeys \"{enter}\"打开记事本,输入东西后保存为e盘\"my.txt
记事本定时存H盘的程序:
Dim wshshell,autosavetime,txtfilename autosavetime=3000
set wshshell=Wscript.createobject(\"Wscript.shell\") txtfilename=inputbox(\"名称\")
wshshell.run \"notepad\" Wscript.sleep 200
wshshell.appactivate \"无标题记事本\"
wshshell.sendkeys \"^s\" Wscript.sleep 300
wshshell.sendkeys \"h:\\\"
wshshell.sendkeys txtfilename Wscript.sleep 300
wshshell.sendkeys \"%s\" Wscript.sleep autosavetime
while wshshell.appactivate(txtfilename)=true//当记事本打开时循环,如果退出记事本则退出wscript wshshell.sendkeys \"^s\" wscript.sleep autosavetime wend
msgbox \"vbs结束\结束\" msgbox \"再见\结束\" wscript.quit
注意:不能输入e:\\a.txt等待路径的,为什么啊????
VBS自动上网登录博客略
************************************** 文件操作及其属性: 1只读文件 2隐藏文件 4系统文件
16文件夹或目录 32存档文件
1024连接或者快捷方式 例:
set fs =wscript(“scripting.filesystemobject”) set f=fs.getfile(“e:\\index.txt”) msgbox f.attributes
创建文件object.createtextfile创建前一定要检查文件是否存在 Set fso=wscript.createobject(“scripting.filesystemobject”) If fso.fileexists(“e:\\kk.txt”) then Msgbox “已经存在” Else
Set f=fso.createtextfile(“e:\\kk.txt”) End if
若强制覆盖则加上true属性 文件的读写: 1、 打开文件:
Set ts=fso.opentextfile(“c:\\kk.txt”,1,true)
1为只读,2为写入,8为追加 True代表文件不存在则新建 2、 读取文件
Read(x) 读x个字符;readline读一行;readall全部读入 Set ffile=fso.opentextfile(“c:\\kktxt”,1,true) Value=ffile.read(20) Line=ffile.readline Contents=ffile.readall
3、 指针变量:
Atendofstream属性处于文件结尾时返回true 例:
Do while ffile.atendofstream<>true Ffile.read(10) Loop
Column属性当前字符位置的列号 Line属性当前位置的行号 4、 在文件中跳行
skip(x)跳过X个字符 Skipline跳过一行
5、 文件中写入字符
2写入,8追加
write(x)写入x字符串
Writeline(x)写入x代表的一行 Writeblanklines(n)写入n个空行 写完后一定要用close方法关闭
读文件后一定要关闭才能以写的形式打开
******************************************************************
Vbs内部函数: Abs返回绝对值
Array返回含有数组的变体
Asc返回字符串首字母的ascii码
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- igat.cn 版权所有 赣ICP备2024042791号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务