Microsoft KB Archive/895239

= How to register a store event sink using Regevent.vbs on Exchange =

Article ID: 895239

Article Last Modified on 10/25/2007

-

APPLIES TO


 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange Server 2003 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition

-



SUMMARY
This article describes:


 * The step-by-step guide on how to register store event sinks
 * The steps on how to delete store event sinks
 * More examples of commands used for event sink registrations

Note Besides using regevent.vbs to register an event sink, there are also other methods to register event sinks. For example, a developer can complie the codes into .dll files, and then register these .dll files directly on the Exchange server. This article introduces one method of registering event sinks when using regevent.vbs.



MORE INFORMATION
A step-by-step guide on how to register store event sinks

Before you use regevent.vbs to register the event sink VB script, you need to register a new COM+ application on the Exchange server to properly execute script-based store events. Please follow the steps below:


 * 1) To start the Component Services console, click Start, select Programs, Administrative Tools, and Component Services.
 * 2) In the Component Services snap-in, expand the list in the following order: Component Services, Computers, and My Computer.
 * 3) Right-click COM+ Applications in the left pane, and select New and Application.
 * 4) Click Next and then choose the &quot;Create An Empty Application&quot; button.
 * 5) Enter ScriptEventSink as the name for the new application.
 * 6) Confirm that the Server Application radio button is selected and click Next.
 * 7) Click Next and click Finish.
 * 8) Select a user that will have owner permissions for the application you are creating, or choose the current user by selecting &quot;Interactive User - The Current Logged On User&quot; radio button.

Note If you choose Interactive User, make sure the account that you are currently logged on with has one of the following permissions:
 * 1) * Explicit &quot;Full mailbox access&quot; right on the mailbox you plan to publish the sink to
 * 2) * Explicit Allow for the &quot;Receive As&quot; right on the mailbox store
 * 3) Open the newly created COM+ Application you just created, right-click on the Components subfolder, and choose New and, then, select Component.
 * 4) Click Next, then choose Install New Component(s).
 * 5) Browse the file system and select \Exchsrvr\Bin\exodbesh.dll. Click Next and Finish.

After registering the new COM+ application, you need to write the event sink VB script file. Here is a sample event sink that does nothing but log its' existence: 

Option Explicit

Public Sub ExStoreEvents_OnSave(pEventInfo, bstrURLItem, lFlags)

LogFile &quot;ExStoreEvents_OnSave&quot;

End Sub

public Sub ExStoreEvents_OnDelete(pEventInfo, bstrURLItem, lFlags)

LogFile &quot;ExStoreEvents_OnDelete&quot;

End Sub

Public Sub ExStoreEvents_OnSyncSave(pEventInfo, bstrURLItem, lFlags)

LogFile &quot;ExStoreEvents_OnSyncSave&quot;

End Sub

Public Sub ExStoreEvents_OnSyncDelete(pEventInfo, bstrURLItem, lFlags)

LogFile &quot;ExStoreEvents_OnSyncDelete&quot;

End Sub

public Sub LogFile(MyString)

Dim fso

Dim txtfile

Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)

Set txtfile = fso.OpenTextFile(&quot;c:\LogFile.log&quot;, 8, True)

txtfile.WriteLine (MyString)

txtfile.Close

End Sub

 We assume that the sink is now saved in the testscript.vbs., you can now register this event sink VB script using the following steps:
 * 1) Click Start, select Run, and type &quot;cmd&quot; (without the quotation marks) to enter the command prompt.
 * 2) Change the directory to \Exchsrvr\Bin and type the following 2 commands:

regsvr32 exodbesh.dll

regsvr32 exodbprx.dll
 * 1) Copy the regevent.vbs (located in the \Program Files\Exchange SDK\SDK\Support\OLEDB\Scripts directory.) and the event sink VB script files onto the root of the C drive.
 * 2) Start the command prompt, and change to the directory of C:\. Type the command to run the regevent.vbs. The following command is one example:

cscript regevent.vbs add &quot;onsave;ondelete&quot; ExOleDB.ScriptEventSink.1 &quot;file://./backofficestorage/contoso.com/MBX/smith/inbox/testsink&quot; -m deep -file &quot;c:\testscript.vbs&quot;

Note This command is used to register the event sink VB script named testscript.vbs in the Inbox of the mailbox named smith. In the command above, you replace contoso.com with the default domain name referenced on the &quot;Local path&quot; field in the Virtual Directory tab of the Exchange virtual directory properties in the Internet Information Services snap-in.

How to delete store event sinks

If you want to delete the event sink you registered in a particular mailbox, you can perform the following steps:
 * 1) Start the command prompt, and change to the directory where the regevent.vbs is located.
 * 2) Type the command to run regevent.vbs. The following code is one example of the command:

cscript regevent.vbs delete &quot;file://./backofficestorage/contoso.com/MBX/smith/inbox/testsink&quot;

More examples of commands for event sink registrations

Example 1

The above command example is to register a specific mailbox. To register event sinks to a specific store with the regevent.vbs script, here is an example:

cscript regevent.vbs add OnSyncSave test.sink &quot;file://./backofficestorage/contoso.com/MBX/SystemMailbox{9ADEA9EA-3924-401F-9C70-0 3B6B7378C9D}/StoreEvents/GlobalEvents/testsink&quot; -m deep

In the above command, the event sink is actually registered to the system mailbox named SystemMailbox{GUID} in the mailbox store. To determine the GUID:


 * 1) In the Exchange System Manager, find the mailbox store that you want to register the event sink to.
 * 2) Select the &quot;Mailboxes&quot; node under the mailbox store to see the list of its' mailboxes. You will see a mailbox called &quot;SystemMailbox{GUID}.&quot; The GUID is the GUID you want.

Example 2

The following example uses the RegEvent script to register an OnSyncSave event to a mailbox:

cscript regevent.vbs add OnSyncSave ExOleDB.ScriptEventSink.1 &quot;file://./backofficestorage/contoso.com/user1/inbox/eventsink1&quot; -m deep -file &quot;c:\script1.vbs&quot;

Example 3

The following example uses the regevent script to register an OnSave and OnDelete event to the public folder named folder1 under the Public Folders tree:

cscript regevent.vbs add &quot;OnSave;OnDelete&quot; ExOleDB.ScriptEventSink.1 &quot;file://./backofficestorage/contoso.com/Public Folders/folder1/testsink&quot; -m deep -file &quot;c:\vbscript1.vbs&quot;

