This article will introduce in detail how to use CreateObject and WScript. CreateObject in VBS in vb. You can refer to it.
Many new VBS users are confused about the differences between CreateObject and WScript. CreateObject. Why do some code use CreateObject, while others use WScript. CreateObject?
Differences between CreateObject and WScript. CreateObject:
Provides the WScript object method. Similar to the relationship between internal commands and external commands in batch processing. In vbs, createobjectis always available, and wscript.createobjectcan only be used when the customer is wscript.exeand cscript.exe. It cannot be used in other host environments such as WMI, QTP, SecureCRT, and EmEditor.
Differences between CreateObject and WScript. CreateObject:
If you only use the first parameter, the CreateObject and WScript. CreateObject are almost the same. But if you want to use the second parameter, the two are completely different. The second parameter of CreateObject is used to create an object on the remote server through DCOM, while the second parameter of WScript. CreateObject is used to create a local object and respond to events.
A simple example of Event Response:
The Code is as follows: |
Copy code |
Dim IE Set IE = WScript. CreateObject ("InternetExplorer. Application", "IE _") IE. Visible = True IE. Navigate http://www.bKjia. c0m Do WScript. Sleep 1000 Loop Sub IE_OnQuit () MsgBox "disabling Demon's Blog" WScript. Quit |
The difference between End SubCreateObject and WScript. CreateObject is three:
Because CreateObject is a VBS built-in function and does not need to be called through COM, CreateObject is a little faster than WScript. CreateObject (although almost negligible ):
The Code is as follows: |
Copy code |
T = Timer For 1 To 100000 Set WshShell = WScript. CreateObject ("Wscript. Shell ") Next WScript. Echo Timer-t 'By Demon 'Http: // www.hzhuti.com T = Timer For 1 To 100000 Set WshShell = CreateObject ("Wscript. Shell ") Next |
WScript. Echo Timer-tDemon suggestion: Try to use the CreateObject function unless you need to respond to the event. There are at least three advantages: Better portability, faster speed, and shorter code.