You access an existing ReplicationInstance object by calling either the ReplicationServer.EnumReplications or ReplicationProject.EnumReplications method, as in the following example, where ReplProject is the name of the project and ReplInst is the name you give to the ReplicationInstance object:
Option Explicit
On Error Resume Next
const OPEN_EXISTING_PROJECT = 2
const REPL_STATE_COMPLETE = 3
const CRS_ERROR_NO_MORE_ITEMS = 0&80003B17
dim ReplServer
set ReplServer = CreateObject("Crsapi.ReplicationServer")
ReplServer.Initialize("")
dim ReplProject
set ReplProject = ReplServer.OpenProject("MyProject", OPEN_EXISTING_PROJECT)
Dim ReplInst
dim Iterator
Iterator = 0
dim ReplError
do while True
'Clear any error text
Err.Clear
'Get the next replication instance
set ReplInst = ReplProject.EnumReplications(REPL_STATE_COMPLETE, Iterator)
'Display error message and quit if empty object returned
if IsEmpty(ReplInst) then
Wscript.Echo "Empty replication instance returned."
exit do
end if
'Quit if "No more items" error
ReplError = Err.Number
if ReplError = CRS_ERROR_NO_MORE_ITEMS then exit do
'Now you have a valid replication instance
...
Loop
'Release objects
set ReplInst = Nothing
set ReplProject = Nothing
set ReplServer = Nothing
Note You can access the replication instances of any or all of the projects on a server by using the ReplicationServer.EnumReplications method.
After you have an instance of a ReplicationInstance object, use the ReplicationInstance.Query method to ensure that you have the latest information.