none
Stop Protection event in MSWord 2010 RRS feed

  • Question

  • Hi everyone..

    I am writing an add in to MSWord 2010 in C#. Can any body please tell me how to get the notification in my add in when the user clicks on the

    "stop protection" button (That appears on the right of the word document when the user tries to edit the protected document).

    For any replies thanks in advance..


    Wednesday, June 13, 2012 4:26 AM

Answers

  • Hi Anil,

    There is no way to repurpose the unprotect button. It is a button private to the "Restrict Formatting and Editing" custom task pane, a button we cannot identify so we cannot edit its "OnAction" method. The OnAction is a call to Microsoft.Office.Word.Interop._Document.Unprotect where the signature allows an optional parameter - the password. We can't override the method nor sink the click event - that's done internally in the _Document object's code.

    One possible hack would to create a custom action pane, size it so it would cover the bottom of the "Restrict Formatting and Editing" task pane - hence hiding the "Your Permissions" portion of that task pane, and show your own button with its own OnAction for the click event.

    That would be a messy hack. You might be better off by writing a thread that examines the document's 'protected' status periodically - say once every 10 milliseconds. If the status has changed take the action you want.

    Someone else may have other ideas about a modification in your design.


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Wednesday, June 20, 2012 1:23 PM
    Moderator

All replies

  • I am writing an add-in for word2010 in C#, VS 2010 is the IDE.

    Is there any way to access the "stop protection" button on document protection task pane..?

    I can able to access the task pane using the fallowing code.. But not the "stop protection" button.

    Word.TaskPane taskPane = (Word.TaskPane)Globals.ThisAddIn.Application.TaskPanes[Word.WdTaskPanes.wdTaskPaneDocumentProtection];

    Please tell me if there is any way to achieve it.

    Friday, June 15, 2012 5:42 AM
  • Hi Anil Kandula,

    Welcome to the MSDN forum! 

    As far as I know, there isn't a built-in event for this procedure. You may try to use Process Monitor to monitor the messages in word.

    Thanks. 


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Friday, June 15, 2012 9:16 AM
    Moderator
  • Hi Yoyo Jiang,

    Thanks for responding..

    Can we intercept the command related with that "stop protection" button using it's idMso..?

    If yes can you please provide me the idMso of that command. And the signature of the call back function i need to register.

    Otherwise, Do i need to go for hooking..?

    Friday, June 15, 2012 9:51 AM
  • What are you trying to achieve? Note that any protection set via the Restrict Formatting and Editing task pane can be easily circumvented by inserting the protected document into a newly created (unprotected) document.

    Stefan Blom, Microsoft Word MVP
    Friday, June 15, 2012 2:02 PM
  • Hi Stefan Blom,

    Thanks for your valuable answer. What i am trying to achieve is i want to get the notification in my add-in when the "stop protection" button on my document is clicked. So that, i can able to do some customized actions. By reading and searching forums i came to know that  we can able to do these kind of stuff using re-purposing concept. So can we re-purpose the "stop Protection" using it's idMso..?

    Monday, June 18, 2012 4:42 AM
  • Hi Anil,

    Thanks for posting in the MSDN Forum.

    There seems no "stop protection" button on the taskpan which your mentioned. And I want to know which kind of proteced way you used in your issue.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 6:19 AM
    Moderator
  • Hi, Anil

    Actually I don't understand why you want to register this event?

    The "Stop Protection" in the task pane calls ActiveDocument.Unprotect method in the background.  It's documented here: http://office.microsoft.com/client/helppreview14.aspx?AssetId=HV080051988&lcid=1033&NS=WINWORD%2EDEV&Version=14&tl=2&queryid=&respos=1&HelpID=vbawd10%2Echm158007417

    I have searched the public control ids document for this control, but it's not in the list. So we're unable to get its idMso.

    with regards,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Monday, June 18, 2012 8:39 AM
    Moderator
  • Hi Anil,

    Thanks for posting in the MSDN Forum.

    There seems no "stop protection" button on the taskpan which your mentioned. And I want to know which kind of proteced way you used in your issue.

    Have a good day,

    Tom


     

    Once you have clicked Yes, Start Enforcing Protection there certainly is a button to stop the protection.


    Stefan Blom, Microsoft Word MVP
    Monday, June 18, 2012 6:14 PM
  • Hi Forrest Guo,

    Thanks for responding..

    We are maintaining our own digital signatures on the word document irrespective of ms word built in signature mechanism.

    We protect the signed document to prevent it from editing. Word un-protects the protected document when the user clicks on the "stop protection" button to enable the editing.

    So what i want to do is, Just remove my signatures on the document when the user clicks on the "stop protection" button by re-purposing it.

    If that is not possible i want to disable the stop protection button permanently.

    Thanks in advance for any replies.

    Tuesday, June 19, 2012 5:12 AM
  • Anil,

    I will consult other people to see if there's a way to disable the stop protection button. Please wait some time.

    thanks,


    Forrest Guo | MSDN Community Support | Feedback to manager

    Tuesday, June 19, 2012 5:30 AM
    Moderator
  • Ok Forrest Guo. I am thank full for that..
    Tuesday, June 19, 2012 10:51 AM
  • Hi Anil,

    There is no way to repurpose the unprotect button. It is a button private to the "Restrict Formatting and Editing" custom task pane, a button we cannot identify so we cannot edit its "OnAction" method. The OnAction is a call to Microsoft.Office.Word.Interop._Document.Unprotect where the signature allows an optional parameter - the password. We can't override the method nor sink the click event - that's done internally in the _Document object's code.

    One possible hack would to create a custom action pane, size it so it would cover the bottom of the "Restrict Formatting and Editing" task pane - hence hiding the "Your Permissions" portion of that task pane, and show your own button with its own OnAction for the click event.

    That would be a messy hack. You might be better off by writing a thread that examines the document's 'protected' status periodically - say once every 10 milliseconds. If the status has changed take the action you want.

    Someone else may have other ideas about a modification in your design.


    Please remember to mark the replies as answer if they help and unmark them if they provide no help. and click "Vote as Helpful" this and other helpful posts, so other users will see your thread as useful. Best Regards, Chris Jensen

    Wednesday, June 20, 2012 1:23 PM
    Moderator