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.appli
2、cationCheckCOM-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 e
3、nsure 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
4、ifend functionsub 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, vbExclamationen
5、d 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 following components: internetexplorer.application scripting.filesystemobjectChe
6、ckCOM-end of COM-object checking code-set ie = CreateObject(“InternetExplorer.Application“)title = “My Output Window“page = “JavaScript:“ & title _& “ie.navigate page wait for the page to be fully initialized:doloop while ie.ReadyState0 thenCOMExists = falseelseCOMExists = trueend ifend functionsub
7、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 ifif not COMExis
8、ts(“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 (C) 2000 by D
9、r. T. Weltner - all rights reserved. 5-4.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 scripting.filesystemobjectCheckCOM-end of COM-object checking code- this statement invo
10、kes the event sink feature:set ie = WScript.CreateObject(“InternetExplorer.Application“, _“event_“)title = “My Output Window“page = “JavaScript:“ & title _& “ie.navigate page wait for the page to be fully initialized:doloop while ie.ReadyState0 thenCOMExists = falseelseCOMExists = trueend ifend func
11、tionsub 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 ifif not
12、 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 (C) 2
13、000 by Dr. T. Weltner - all rights reserved. 5-5.VBS-the following lines have been added to ensure all required COM objects are available on your system. script uses the following components: typelib.decoder scripting.dictionaryCheckCOM-end of COM-object checking code-set typelib = CreateObject(“typ
14、elib.decoder“) use a dictionary to keep track of duplicate entries:set dict = CreateObject(“scripting.dictionary“) check interfaces defined in this file:typelibfile = “shdocvw.dll“ enumerate available interfaces:set interfaces = typelib.GetInterfaces(typelibfile)list = “Interfaces in “ & typelibfile
15、 & “:“ & vbCr & vbCr read all interfaces and put into list:for each interface in interfaces check whether entry is a duplicate entry:if not dict.Exists(interface) then add to list only if new entrydict.Add interface, 0list = list & interface & vbCrend ifnextMsgBox list - the following code had been
16、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.RegRead(“HKCR“ & name & “)if err.number0 thenCOMExists = false
17、elseCOMExists = trueend ifend functionsub CheckCOMif not COMExists(“typelib.decoder“) thenmsg=“COM-Object “typelib.decoder“ is required. This object is currently not installed on your system.“ & vbCrmsg = msg & “Install the TYPELIB component from CD“ & vbCrMsgBox msg, vbExclamationend ifif not COMEx
18、ists(“wscript.shell“) thenmsg=“COM-Object “wscript.shell“ 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 (C) 2000 by Dr. T. Weltner - all righ
19、ts reserved. 5-7.VBS-the following lines have been added to ensure all required COM objects are available on your system. script uses the following components: scripting.filesystemobject internetexplorer.applicationCheckCOM-end of COM-object checking code- Open IE Window without scroll barset window
20、 = OpenWindow(“My Output Window“, false) use window:content = InputBox(“Please enter some text!“)PrintNew window, “ & content & “MsgBox “I will now list all files on drive C:!“ list all filesset fs = CreateObject(“Scripting.FileSystemObject“)set folder = fs.GetFolder(“C:“)for each file in folder.fil
21、esPrint window, file.name & “nextsub event_onQuitMsgBox “Hey! You closed my output window!“, vbExclamationWScript.Quitend subfunction OpenWindow(title, scrolling)set ie = WScript.CreateObject(“InternetExplorer.Application“, _“event_“) add attribute to body-tag to hide scroll bar if appropriate:if sc
22、rolling then scroller = “scroll = no“end ifpage = “JavaScript:“ & title _& “ie.navigate page turn off toolbarsie.Toolbar = false turn off status barie.Statusbar = falsedoloop while ie.ReadyState0 thenCOMExists = falseelseCOMExists = trueend ifend functionsub CheckCOMif not COMExists(“scripting.files
23、ystemobject“) 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 ifif not COMExists(“internetexplorer.application“) thenmsg=“COM-Object “int
24、ernetexplorer.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 of COM object checking code (C) 2000 by Dr. T. Weltner - all rights reserved. 5-8.
25、VBS-the following lines have been added to ensure all required COM objects are available on your system. script uses the following components: scripting.filesystemobject internetexplorer.applicationCheckCOM-end of COM-object checking code-set window = OpenWindow(“My Output Window“, 400, 200)content
26、= InputBox(“Please enter some text!“)PrintNew window, “ & content & “MsgBox “I will now list all files on drive C:!“ list all filesset fs = CreateObject(“Scripting.FileSystemObject“)set folder = fs.GetFolder(“C:“)for each file in folder.filesPrint window, file.name & “nextsub event_onQuitMsgBox “Hey
27、! You closed my output window!“, vbExclamationWScript.Quitend subfunction OpenWindow(title, width, height)set ie = WScript.CreateObject(“InternetExplorer.Application“, _“event_“)page = “JavaScript:“ & title _& “ie.navigate pageie.Toolbar = falseie.Statusbar = falsedoloop while ie.ReadyStatescreenWid
28、th then width=screenWidthif heightscreenHeight then height=screenHeightie.Width = widthie.Height = heightie.left = Fix(screenWidth - width)/2)ie.top = Fix(screenHeight - height)/2)ie.visible = true return reference to IE object:Set OpenWindow = ieend functionsub PrintNew(obj, text)obj.document.body.
29、innerHTML = textend subsub Print(obj, text)obj.document.body.insertAdjacentHTML “beforeEnd“, textend sub - 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 machine
30、set cwsh = CreateObject(“WScript.Shell“)on error resume nextdummy = cwsh.RegRead(“HKCR“ & name & “)if err.number4screenWidth = ie.document.parentWindow.screen.availWidthscreenHeight = ie.document.parentWindow.screen.availHeight limit size to max avail spaceif widthscreenWidth then width=screenWidthi
31、f heightscreenHeight then height=screenHeightie.Width = widthie.Height = heightie.left = Fix(screenWidth - width)/2)ie.top = Fix(screenHeight - height)/2)ie.visible = true return reference to IE object:Set OpenWindow = ieend function - the following code had been automatically added to ensure all re
32、quired 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.number4screenWidth = ie.document.parentWindow.screen.availWidthsc
33、reenHeight = ie.document.parentWindow.screen.availHeight limit size to max avail spaceif widthscreenWidth then width=screenWidthif heightscreenHeight then height=screenHeightie.Width = widthie.Height = heightie.left = Fix(screenWidth - width)/2)ie.top = Fix(screenHeight - height)/2)ie.visible = true
34、 return reference to IE object:Set OpenWindow = ieend function - 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
35、 error resume nextdummy = cwsh.RegRead(“HKCR“ & name & “)if err.number0 thenCOMExists = falseelseCOMExists = trueend ifend functionsub CheckCOMif not COMExists(“typelib.decoder“) thenmsg=“COM-Object “typelib.decoder“ is required. This object is currently not installed on your system.“ & vbCrmsg = ms
36、g & “Install the TYPELIB component from CD“ & 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 Hos
37、t!“ & vbCrMsgBox msg, vbExclamationend ifif not COMExists(“wscript.shell“) thenmsg=“COM-Object “wscript.shell“ is required. This object is currently not installed on your system.“ & vbCrmsg = msg & “Reinstall the Windows Scripting Host!“ & vbCrMsgBox msg, vbExclamationend ifif not COMExists(“scripti
38、ng.dictionary“) thenmsg=“COM-Object “scripting.dictionary“ 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 (C) 2000 by Dr. T. Weltner - all rig
39、hts reserved. 5-12.VBS-the following lines have been added to ensure all required COM objects are available on your system. script uses the following components: typelib.decoder scripting.filesystemobject wscript.shell scripting.dictionary internetexplorer.applicationCheckCOM-end of COM-object check
40、ing code- make sure you have installed the custom COM object as outlined in the book change this path to the folder you want to store your documentation in:docu = “C:documentation“ change this to false if you dont want a shortcut to your documentation folder on your desktop:link = true we need acces
41、s to a couple of COM objects:set typelib = CreateObject(“typelib.decoder“)set fs = CreateObject(“Scripting.FileSystemObject“)set wshshell = CreateObject(“WScript.Shell“)set dict = CreateObject(“scripting.dictionary“) ask which type library to decode:lib = InputBox(“Which Type Library do you want to decode?“, _, “mshtml.tlb“) do some checks: does the folder name end with “?if not right(docu,1)=“ then docu = docu & “ does the typelib file exist and is it a valid typelib?