different expiration date for different users in word 2003

V

Vinita Batra

Hi,

I am using office automation apis to apply RMS protection.
I want to set the different expiration date for different users.
i am using following code


DateTime dtExpireDate = new DateTime(2008, 10, 8);
Microsoft.Office.Core.MsoPermission per =
Microsoft.Office.Core.MsoPermission.msoPermissionPrint;
DateTime dtExpireDate1 = new DateTime(2008, 11, 8);
Microsoft.Office.Core.MsoPermission per1 =
Microsoft.Office.Core.MsoPermission.msoPermissionChange;


oWordDoc.Permission.Add("user1.abc@domainname", per, dtExpireDate);
oWordDoc.Permission.Add("user2.abc@domainname", per1, dtExpireDate1);
and then i save the document.


But when both users check that document, then same expiration date
of( 2008, 10, 8); is peresent.


How can i set the the separate expiration date for sepate users for
the same document.
Please hepl me in this.


Thanks and Regards,
Vinita.
 
A

alborg

Hi Vinita:

I've never used the "permission" property, and on a Google search, couldn't
come up with vba either- maybe some of the gurus here can help you there if
you absolutely wish to continue that route.

What I use, is the Window's registry. It's pretty simple to write stuff back
and forth to the registry. I've used it in both my MS Access and MS Word
projects to lock people out, say, after a certain amount of openings or after
a certain date. The following code below checks for the "szUser" and sees
what their profile is:

Function ITO()
On Error GoTo ITO_Err
'***************************************************************************
'Purpose:
'Comments: 1. Compiles all code in the database if it is uncompiled
' 2. Writes usage info to custom database properties
' 3. Writes usage info to the Registry
' 4. Sets flag to indicate if dbs is due for compacting
'***************************************************************************

'Find out how many times this particular database has been opened
Call IncrementTimesOpened

'Write information to the Registry to indicate usage for this user
lngProfileTimesOpened = GetSetting("z_m_d_s", "Startup", "UsageCount", 1)
SaveSetting "z_m_d_s", "Startup", "UsageCount", lngProfileTimesOpened + 1
SaveSetting "z_m_d_s", "Startup", "LastUsed", Format$(Now(), "yyyy.mm.dd
hh:nn:ss")

ITO_Exit:
Exit Function

ITO_Err:
'Turn screen updating back on
Application.Echo True

'Now handle the error
Select Case err.Number
Case Else
Call GlobalErr("ITO", err.Number)
Resume ITO_Exit
Resume
End Select

End Function

Sub IncrementTimesOpened()
'***************************************************************************
'Purpose: To set a dbs property indicating the number of times the
' database has been opened
'Parameters: None
'Returns: Nothing
'***************************************************************************

On Error GoTo IncrementTimesOpened_Err
Dim rst As Recordset
lngDBTimesOpened = CurrentDb.Properties("TimesOpened")
If IsNull(lngDBTimesOpened) Then
MsgBox "It's null!"
lngDBTimesOpened = 0
Else
Set dbs = CurrentDb
SQLStmt = "SELECT DISTINCTROW SUP.* FROM SUP;"
Set rst = dbs.OpenRecordset(SQLStmt, dbOpenDynaset) 'alborgggg
With rst
.MoveLast
.MoveFirst
If !Rest = True Then
lngDBTimesOpened = 0
Else
lngDBTimesOpened = lngDBTimesOpened + 1
End If
.Edit
!Rest = False
.UPDATE
.Close
End With
dbs.Close
End If
CurrentDb.Properties("TimesOpened") = lngDBTimesOpened

IncrementTimesOpened_Exit:
Exit Sub

IncrementTimesOpened_Err:
Select Case err.Number
Case 3270 'Error code for "Property not found"
Set pty = CurrentDb.CreateProperty("TimesOpened", dbDate, 0)
CurrentDb.Properties.Append pty
Resume
Case Else
Call GlobalErr("IncrementTimesOpened", err.Number)
Resume IncrementTimesOpened_Exit
Resume
End Select
End Sub

A good discussion on this can be also found here-

1)
http://www.tech-archive.net/Archive...blic.scripting.vbscript/2006-09/msg00644.html
2) http://archive.baarns.com/word/faq/wd_macr.asp

Cheers,
Al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top