04.08.2013 Views

The Windows Scripting Host - dFPUG-Portal

The Windows Scripting Host - dFPUG-Portal

The Windows Scripting Host - dFPUG-Portal

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Print Article<br />

A quick word about debugging and handling errors<br />

No programming environment is complete without a full-featured debugging environment. <strong>The</strong> WSH is no exception, as it also<br />

has a full-featured debugger. As far as error handling is concerned, VBScript doesn't have a global error handler. Rather,<br />

errors need to be handled on an in-line basis. <strong>The</strong> following code demonstrates how to deal with errors on an in-line basis:<br />

On Error Resume Next<br />

dim objxl<br />

Set objXL = WScript.CreateObject("Excel.Application")<br />

objxl.foo ' reference a non-existent Excel Method<br />

If Err.Number > 0 <strong>The</strong>n<br />

Call ErrorProc<br />

End If<br />

Sub ErrorProc<br />

msgbox err.description<br />

End Sub<br />

If no error trapping exists, you'll be prompted with a dialog box asking if you wish to debug the application. Figure 1 illustrates<br />

how the code will appear in the script debugger.<br />

Figure 1. <strong>The</strong> Microsoft Script Debugger uses the same IDE as Visual InterDev and Visual J++ 6.0.<br />

<strong>The</strong> WSH objects<br />

<strong>The</strong>re are two primary objects contained within the WSH. <strong>The</strong> following code illustrates how these objects can be created:<br />

WSHshell = CreateObject("Wscript.Shell")<br />

WSHNetwork = CreateObject("Wscript.Network")<br />

Both the shell and network objects are hosted by the wshom.ocx ActiveX Control.<br />

Complete documentation for the WSHShell and WSHNetwork Objects can be found by navigating to the following URLs:<br />

http://www.microsoft.com/iis/support/iishelp/iis/htm/asp/wsho7t84.htm for the WSHShell object<br />

http://www.microsoft.com/iis/support/iishelp/iis/htm/asp/wsho20qc.htm for the WSHNetwork object<br />

Seite 2 von 6<br />

Shell object properties and methods<br />

Environment<br />

This property provides access to the environment collection. Information such as number of processors, paths, OS, and so<br />

forth can be determined from this collection.<br />

http://foxtalknewsletter.com/ME2/Audiences/Segments/Publications/Print.asp?Module=...<br />

31.01.06

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!