首先创建一个【主程序.vbs】,代码如下:
Dim MainContainer, Window, Document
Set MainContainer = CreateObject("InternetExplorer.Application")
MainContainer.Navigate "about:blank"
MainContainer.Visible = True
Set Window = MainContainer.Document.parentWindow
Set Document = Window.document
Dim TextBox1
Set TextBox1 = Document.CreateElement("<input type='text' id='TextBox1'>")
Document.body.appendChild TextBox1
dim a,b,c
a=inputbox("请输入开始快捷键(F0~F9)")
b=inputbox("请输入结束快捷键(F0~F9)")
c=inputbox("请输入循环时间(秒)")
dim fso,w
Set fso = CreateObject("Scripting.FileSystemObject")
Set w=fso.OpenTextFile ("临时.txt",2,1)
w.Write ( a &vbcrlf &b)
w.Close
dim ws
set ws = createobject("wscript.shell")
ws.run "开始.vbs"
ws.run "结早皮束.vbs"
i=c
do while ss
ss = fso.fileExists(strFilePath)
i=i-1
textbox1.value=i
j=j+1
if j=30 then ss=true
wscript.sleep 1000
loop
msgbox "程序结束"
textbox1.value="程序结束"
ws.DeleteFile("临时.txt"), True
ws.run "taskkill /im WScript.exe /f"
再创建一个【开始.vbs】,代码如下:
Dim strDllPath
strDllPath = Replace(WScript.ScriptFullName,WScript.ScriptName,"dynwrap.dll") '获取DLL文件的绝对路径
RegisterCOM strDllPath '注册DynamicWrapper组件
Dim g_objConnectAPI
Set g_objConnectAPI = CreateObject("DynamicWrapper") '创建全局的DynamicWrapper组件对象实例
'以下为声明将要用到的Win32API函数
With g_objConnectAPI
.Register "user32.dll","GetAsyncKeyState","i=l","f=s","r=l"
End With
dim b,fso
Set fso = CreateObject("scripting.filesystemobject")
Set X=fso.OpenTextFile("临时.txt",1)
a="[" &X.ReadLine &"]"
do until thekey=a
thekey=GetThePressKey()
wscript.sleep 1
loop
Set fso = CreateObject("Scripting.FileSystemObject")
Set w=fso.OpenTextFile ("运行.txt",2,1)
w.Write ("")
w.Close
还有【结束.vbs】,代码如下:
Dim strDllPath
strDllPath = Replace(WScript.ScriptFullName,WScript.ScriptName,"dynwrap.dll") '获取DLL文件的绝对路径
RegisterCOM strDllPath '注册DynamicWrapper组件
Dim g_objConnectAPI
Set g_objConnectAPI = CreateObject("DynamicWrapper") '创建全局的DynamicWrapper组件对象实例
'以下为声明将要用到的Win32API函数
With g_objConnectAPI
.Register "user32.dll","GetAsyncKeyState","i=l","f=s","r=l"
End With
dim b,fso
Set fso = CreateObject("scripting.filesystemobject")
Set X=fso.OpenTextFile("临时.txt",1)
X.ReadLine
b="[" &X.ReadLine &"]"
do until thekey=b
thekey=GetThePressKey()
wscript.sleep 1
loop
CreateObject("Scripting.FileSystemObject").DeleteFile("运行.txt"), True
这三个文件缺一不可,是互相配合的。
主程序.vbs正常,开始.vbs和结束.vbs出错。不知道怎么改了。你可以把这两个VBS的代码发在百度上提问。
首先VBS是团型个脚本语言,一种解迹并释型执行语言,所以它不要IDE和编译,只要塌州猜有宿主程序如Wscript.exe在它就可以被执行。vbs文件本身是文本文件如bat(批处理),它们本身是不具有执行机动性的,由于在注册表中设置了关联,所以每当双击或者满足运行vbs文件的条件时,系统就会通知宿主程序(Wscript.exe)来分析这个vbs文档,然后经过解释后交给后台处理。换言之Wscript.exe就是VBS的解释器,将vbs代码转化为计算机可识别和执行的过程全交由Wscript处理。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)