《Windows脚本编程核心技术精解-随书示例脚本-第五章(精品)》由会员分享,可在线阅读,更多相关《Windows脚本编程核心技术精解-随书示例脚本-第五章(精品)(38页珍藏版)》请在金锄头文库上搜索。
1、 5-1.VBS2 5-2.VBS4 5-3.VBS6 5-4.VBS8 5-5.VBS11 5-6.VBS13 5-7.VBS15 5-8.VBS18 5-9.VBS21 5-10.VBS24 5-11.VBS27 5-12.VBS30 5-13.VBS37 5-1.VBS -the following lines have been added to ensure all required COM objects are available on your system. script uses the following components: internetexplorer.appl
2、ication CheckCOM-end of COM-object checking code- set ie = CreateObject(InternetExplorer.Application)MsgBox Object Type: & TypeName(ie)ie.visible = trueMsgBox Internet Explorer is visible now!ie.visible = falseMsgBox Now its hidden!ie.Quit - the following code had been automatically added to ensure
3、all required COM objects are installed.function COMExists(name) checks whether a specific COM object is installed on your local machineset cwsh = CreateObject(WScript.Shell)on error resume nextdummy = cwsh.RegRead(HKCR & name & )if err.number0 thenCOMExists = falseelseCOMExists = trueend ifend funct
4、ion sub CheckCOMif not COMExists(internetexplorer.application) thenmsg=COM-Object internetexplorer.application is required. This object is currently not installed on your system. & vbCrmsg = msg & Install the Internet Explorer Version 4.0 or above. & vbCrMsgBox msg, vbExclamationend ifend sub- end o
5、f COM object checking code (C) 2000 by Dr. T. Weltner - all rights reserved. 5-2.VBS -the following lines have been added to ensure all required COM objects are available on your system. script uses the following components: internetexplorer.application CheckCOM-end of COM-object checking code- set
6、ie = CreateObject(InternetExplorer.Application)scriptname = WScript.ScriptFullNamepath = left(scriptname, InstrRev(scriptname, )filename = path & showme.htmMsgBox Now loading & filenameie.navigate filenameie.visible = trueMsgBox Internet Explorer is visible now!, vbSystemModalMsgBox Type of document
7、: & TypeName(ie.document)ie.Quit - the following code had been automatically added to ensure all required COM objects are installed.function COMExists(name) checks whether a specific COM object is installed on your local machineset cwsh = CreateObject(WScript.Shell)on error resume nextdummy = cwsh.R
8、egRead(HKCR & name & )if err.number0 thenCOMExists = falseelseCOMExists = trueend ifend function sub CheckCOMif not COMExists(internetexplorer.application) thenmsg=COM-Object internetexplorer.application is required. This object is currently not installed on your system. & vbCrmsg = msg & Install th
9、e Internet Explorer Version 4.0 or above. & vbCrMsgBox msg, vbExclamationend ifend sub- end of COM object checking code (C) 2000 by Dr. T. Weltner - all rights reserved. 5-3.VBS -the following lines have been added to ensure all required COM objects are available on your system. script uses the foll
10、owing components: internetexplorer.application scripting.filesystemobject CheckCOM-end of COM-object checking code- set ie = CreateObject(InternetExplorer.Application)title = My Output Windowpage = JavaScript: & title _ & ie.navigate page wait for the page to be fully initialized:doloop while ie.Rea
11、dyState4 show page:ie.visible = true now you can dynamically change content:content = InputBox(Please enter some text!)ie.document.body.innerHTML = & content & MsgBox I will now list all files on drive C:! list all filesset fs = CreateObject(Scripting.FileSystemObject)set folder = fs.GetFolder(C:)fo
12、r each file in folder.files ie.document.body.insertAdjacentHTML beforeEnd, _file.name & next - the following code had been automatically added to ensure all required COM objects are installed.function COMExists(name) checks whether a specific COM object is installed on your local machineset cwsh = C
13、reateObject(WScript.Shell)on error resume nextdummy = cwsh.RegRead(HKCR & name & )if err.number0 thenCOMExists = falseelseCOMExists = trueend ifend function sub CheckCOMif not COMExists(internetexplorer.application) thenmsg=COM-Object internetexplorer.application is required. This object is currentl
14、y not installed on your system. & vbCrmsg = msg & Install the Internet Explorer Version 4.0 or above. & vbCrMsgBox msg, vbExclamationend ifif not COMExists(scripting.filesystemobject) thenmsg=COM-Object scripting.filesystemobject is required. This object is currently not installed on your system. & vbCrmsg = msg & Reinstall the Windows Scripting Host! & vbCrMsgBox msg, vbExclamationend ifend sub- end of COM object checking code