Subject: Create encrypt replica programmatically
Simple agent which create encypted local replica (no error handling):Option Declare
Private Const wAPIModule = “NNOTES” ’ Windows/32
Private Const NOTE_CLASS_ALL=&H7FFF
Private Const NOTE_CLASS_ALL_PUBLIC=&H06FFF
Private Const NOTE_CLASS_PRIVATE=&H1000
Private Const NOTE_CLASS_ICON=&H0010
Private Const NOTE_CLASS_ACL=&H0040
Private Const NOTE_CLASS_REPLFORMULA=&H0800
Private Const DBCOPY_REPLICA&=&H00000001
Private Const DBCOPY_REPLICA_NAMELIST&=&H01000000
’
Public Const DBCOPY_ENCRYPT_SIMPLE&=&H00000040
Public Const DBCOPY_ENCRYPT_MEDIUM&=&H00000080
Public Const DBCOPY_ENCRYPT_STRONG&=&H00000100
Declare Private Function NSFDbClose Lib wAPIModule Alias “NSFDbClose” _
( Byval hDB As Long) As Integer
Declare Private Function OSPathNetConstruct Lib wAPIModule Alias “OSPathNetConstruct” _
( Byval Path As Long, Byval sServer As String, Byval sFilepath As String, Byval retNetpath As String) As Integer
Declare Function OSLoadString Lib wAPIModule (Byval hModule As Long, Byval iCode As Integer, Byval retBuffer As String, BufferLength As Integer) As Integer
Declare Private Function NSFDbCreateAndCopy Lib wAPIModule Alias “NSFDbCreateAndCopy”( Byval srcDB As Lmbcs String, _
Byval dstDB As Lmbcs String, Byval NoteClass As Integer,Byval limit As Integer, Byval flags As Long, hDB As Long) As Integer
Sub Initialize
Dim s As New NotesSession
Dim newdb As NotesDatabase
Set newdb=CreateLocalReplicaExt(s.CurrentDatabase,DBCOPY_ENCRYPT_STRONG)
If newdb.IsOpen Then
Call s.CurrentDatabase.Replicate(“”)
else
Print “oop’s…”
End If
End Sub
Private Function CreateLocalReplicaExt(db As NotesDatabase, pEncryption As Long) As NotesDatabase
Dim srcpath As String
Dim dstpath As String
Dim hDB As Long
Dim ret As Integer
Dim buf As String
Dim nclass As Integer
Dim flags As Long
Dim dstdb As New NotesDatabase(“”,“”)
If db.server<>“” Then
srcpath=String(1024,0)
dstpath=String(1024,0)
OSPathNetConstruct 0, db.Server, db.FilePath, srcpath
OSPathNetConstruct 0, “”, db.FilePath, dstpath
nclass=NOTE_CLASS_ICON + NOTE_CLASS_REPLFORMULA + NOTE_CLASS_ACL
'too slowly - nclass=NOTE_CLASS_ALL_PUBLIC
flags=DBCOPY_REPLICA + DBCOPY_REPLICA_NAMELIST + pEncryption
ret=NSFDbCreateAndCopy(srcpath,dstpath, nclass, 0, flags ,hDB)
If hDB<>0 Then
NSFDbClose hDB
Call dstdb.Open(“”,db.FilePath)
Else
buf=String$(256, 0)
OSLoadString 0, ret, buf, 255
Print “NSFDbCreateAndCopy:”,ret,buf
End If
Else
Print “source db must be on server”
End If
Set CreateLocalReplicaExt= dstdb
End Function
Enjoy!