CDOLive LLC The Premier Resource for Microsoft Collaboration Data Objects             

Debugging

If you are developing Microsoft Exchange Server Scripting and Routing solutions, it is recommended to write and test your script in a non-production environment before you deploy it on the production machines. There are some caveats about debugging your Microsoft Exchange Server Scripting and Routing scripts. First make sure that the Microsoft Script Debugger is installed properly, on the Microsoft Exchange Server computer.

You have two options to install the Microsoft Script Debugger. First you can install it with the Microsoft Windows NT Server 4.0 Option Pack. After you have started the setup of the Microsoft Windows NT Server 4.0 Option Pack simply select the Microsoft Script Debugger, which is not installed per default.

Another way to install the Microsoft Script Debugger is, start the Control Panel, choose Add/Remove Programs, Internet Explorer 4.0, click Add/Remove, select Add a component to Internet Explorer and click Ok. You will be now redirected to the Microsoft Internet Explorer Update Page. This page will show a list of the available Microsoft Internet Explorer components, which can be installed including the Microsoft Script Debugger. Simply select the Microsoft Script Debugger and start the installation.

To debug a Microsoft Exchange Scripting and Routing script, put a STOP (Microsoft Visual Basic Scripting Edition) or DEBUGGER (Microsoft JScript) statement in your code to have the Microsoft Script Debugger popup. You can step interactive through your code, execute commands and change values of variables. But you cannot change the code while you are in the debugger window. You have to close the debugger, change your code and run the application again.

To check if you have the Microsoft Script Debugger installed, start the Control Panel, choose Add/Remove Programs and search for Microsoft Script Debugger.

You cannot debug Microsoft Exchange Server Scripting and Routing scripts remotely. If you put a STOP (Microsoft Visual Basic Scripting Edition) or DEBUGGER (Microsoft JScript) statement in your code, the Microsoft Script Debugger will popup on the Microsoft Exchange Server computer. If the machine is at another location, you have to use remote control software to access your Microsoft Exchange Server computer.

Make sure that you are logged-on to the Microsoft Exchange Server computer with the same Microsoft Windows NT account, which is used for the Microsoft Exchange Server Event Service. Also the mailbox which is used must have Owner permissions on the system folder Folders\System Folders\Events Root\EventConfig_<Your Servername>. Otherwise the popup window with the Microsoft Script Debugger will not show your script. For more information about permissions, please take a look at The Secrets of Exchange Server Scripting and Routing, Permissions and Security.

Another way to debug your application is to run the Microsoft Exchange Server Event Service program events.exe,  located in the Microsoft Exchange Server directory (e. g. c:\exchsrvr\bin), in a command window on your Microsoft Windows NT Server. Then you get a detailed screen output with the activities of the Microsoft Exchange Server Event Service.

You can also change a registry entry on the Microsoft Exchange Server to get more detailed Microsoft Windows NT EventLog messages. For more information, please take a look at The Secrets of Exchange Server Scripting and Routing, Tips and Tricks.

For more information about Microsoft Script Debugger, please take look at Links @ Microsoft.

If you are running Microsoft Active Desktop and Microsoft Script Debugger on the same machine it is possible that your machine will stop responding. The only supported workaround is to disable the Microsoft Active Desktop. An unsupported way is to rename the Microsoft Script Debugger program file (mdm.exe) located on your windows system directory (e. g. c:\winnt\system32). Note that this produces some wired DCOM error messages in the Windows NT EventLog, which can be ignored.

You can also use the agent log, which is a hidden message in each folder where you have a Microsoft Exchange Server Scripting and Routing script installed. You can access this agent log by opening the particular private or public folder and right click it. Choose Properties, Agents. Select your already installed agent and choose Edit. The new window now shows a button Logs, which stores the agent log information. By default the agent log is empty. You have to put some code inside your Microsoft Exchange Server Scripting and Routing script to get results into the agent log.

This sample debug function can be used to create debugging information at the agent log:

'------------------------------------------------------------------------------
' Name: DebugAppend
' Area: Debug
' Desc: Simple Debugging Function
' Parm: String Text, Bool ErrorFlag
'------------------------------------------------------------------------------

Private Sub DebugAppend(bstrParm,boolErrChkFlag)

    If boolErrChkFlag = True Then
        If Err.Number <> 0 Then
            g_bstrDebug = g_bstrDebug & bstrParm & " - " & cstr(Err.Number) & " " & _
             Err.Description & vbCrLf
            Err.Clear
        End If
    Else
        g_bstrDebug = g_bstrDebug & bstrParm & vbCrLf
    End If
End Sub

You must put the following line inside your Microsoft Exchange Server Scripting and Routing script to create a line with information at the agent log:

Call DebugAppend("Information", False)

Add the following line if you want to get a detailed error description if an error has occurred:

Call DebugAppend("Information", True)

Finally write the results to the agent log at the end of the script:

Script.Response = g_bstrDebug

Note that you only can call the Script.Response one time in your script. This is by design.

You can find a lot of samples which are using this technique at the Code Sample Library.