Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
Set f=fso.CreateTextFile("C:Sample.txt")
WriteLine("VBS")
f.close
set e=fso.getfile(C:Sample.txt)
e.copy("D:Sample.txt")
fso.deletefile(C:Sample.txt)
Wscript.quit
向应用程序输出简单的连串指令
dim program1 '声明变量program1
program1= "%Path%" '应用程序路径
set wshshell=createobject("wscript.shell") '声明饮用函数
set oexec=wshshell.exec(program1) '运行程序
wscript.sleep 2000 '(该行命令未知作用.估计是设定延迟,请高手指点)
wshshell.appactivate "%WindowsName%" '激活运用程序窗口
wshshell.sendkeys "+{%KeyBoardName%}" '第一次输出键盘按键指令前要加+
wshshell.sendkeys "555555" '在程序输入栏中输入运用该系列命令须首先确定程序可以实施连串的键盘操作,这在QQ登录中最适用,如下例。
程序代码
dim program1
program1="D:Program FilesTencentcoralQQ.exe"
set wshshell=CreateObject("wscript.shell")
set oexec=wshshell.exec(program1)
wscript.sleep 2000
wshshell.appactivate "QQ登录"
wshshell.sendkeys "+{TAB}"
wshshell.sendkeys "250481892"
wscript.sleep 2000
wshshell.sendkeys "{TAB}"
wshshell.sendkeys "****************"
wscript.sleep 2000
wshshell.sendkeys "{ENTER}"
Wscript.quit
文件夹的简单操作
Set fso = Wscript.CreateObject("Scripting.FileSystemObject") '声明
Set f = fso.CreateFolder("%PATH%") 创建文件夹
Set e = getFolder(%PATH%) 类似于"绑定目标"
e.copy("%PATH2%") 复制文件夹
fso.deletefolder(%PATH%) 删除文件夹
程序代码
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
Set f = fso.CreateObject("C:sample")
f.copy("D:sample")
fso.deletefolder("C:sample")
'(由上例可以看出,文件夹的操作很多是和文件的操作相通的,因此VBS文件具有很多命令的统一性)
将某一指定文件夹的所有只读文件转为可读文件
Const ReadOnly = 1 '设只读属性对应值为1
Set FSO = CreateObject("Scripting.FileSystemObject") '声明
Set Folder = FSO.GetFolder("%PATH%") '绑定文件夹
Set colFiles = Folder.Files '文件夹所有文件
For Each objFile in colFiles '下列语句应用于文件夹所有文件
If File.Attributes AND ReadOnly Then '这是关键之处,这里应用了If判断语句,来检测文件属性是否为只读
File.Attributes = File.Attributes XOR ReadOnly
'对判断结果为Ture(默认为True)'执行XOR逻辑运算,将其改为可读







