范永根,天魔神谭下载,田敏虎
站长(reterry)推荐此篇文章,想学vbscript的朋友,我建议到微软的官方网站去看,那里的东西很不错,生动幽默,我以前学vbscirpt的时候经常去那里看,而且好多东西,不一定刚开始能看的懂,但不要灰心,把感觉不错的,你可以用本子抄一遍,学习效果会更好,然后下载个vbscirpt帮助文件,微软有的下,然后看看多练习。wmi -- windows management instrumentation
相关链接:
微软《脚本指南》:
msdn wmi scripting primer:
脚本示例1,显示本机总内存
strcomputer = "."
set wbemservices = getobject("winmgmts:\\" & strcomputer)
set wbemobjectset = wbemservices.instancesof("win32_logicalmemoryconfiguration")
for each wbemobject in wbemobjectset
wscript.echo "total physical memory (kb): " & wbemobject.totalphysicalmemory
next
脚本示例2,
strcomputer = "."
set objwmiservice = getobject("winmgmts://" & strcomputer & "/root/cimv2")
strwql = "select * " & _
"from __instancecreationevent " & _
"within 2 " & _
"where targetinstance isa 'win32_process' " & _
"and targetinstance.name = 'notepad.exe'"
wscript.echo "waiting for a new instance of notepad to start..."
set objeventsource = objwmiservice.execnotificationquery(strwql)
set objeventobject = objeventsource.nextevent()
wscript.echo "a new instance of notepad was just started."
在脚本中使用外壳(shell)程序
set objshell = wscript.createobject("wscript.shell")
objshell.run "notepad" '运行记事本
调用命令程序(%comspec%环境变量调用相应操作系统的cmd.exe 或 command.exe)运行脚本,并保持console窗口:
set objshell = createobject("wscript.shell")
objshell.run "%comspec% /k ipconfig"
使用objshell的exec方法代替run方法可将运行返回一个wshscriptexec对象,可对结果显示做更多的控制。
运行脚本exam.vbs:
在命令行下输入:cscript exam.vbs
使用重定向符将脚本运行结果输出到文本文件:
cscript exam.vbs > output.txt //覆盖方式
cscript exam.vbs >> output.txt //保留添加方式
使用filesystemobject输出到文件:
set objfs = createobject("scripting.filesystemobject")
set objnewfile = objfs.createtextfile("output.txt")
objnewfile.writeline "header information -- date: " & now()
objnewfile.close
脚本主机script host:
wscript.exe 基于gui窗口
cscript.exe 基于控制台命令console
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
网友评论