none
Office 2010 dev: HOW TO customize the message in the yellow bar on Application.ProtectedViewWindows.Open <myFilePath> RRS feed

  • Question

  • Dear all,

    Sorry if this has been answered before but I wasn't able to find it, please redirect me to the appropriate thread if necessary.

    I am programmatically using "Application.ProtectedViewWindows.Open <myFilePath>" in Office 2010 to open a document and warn the user that by default she shouldn't modify it.

    I wish I could change the message that appears in the yellow bar associated with protected mode, to give the user some specific information - but I can't find a way to set it. My first try was the ProtectedViewWindow.Caption property, but it actually sets the Office application title bar, which is much less in view than the protected mode yellow bar.

    I've searched over the Internet an answer to that question but was unable to find one. Can anyone help? Thanks in advance!

    - NR

    Sunday, May 20, 2012 4:20 PM

Answers

All replies

  • Hi NR,

    I can see that is a commandbar instance of the Word via Spy++. I hope it can help you.

    Have a good day,

    T.X.


    Monday, May 21, 2012 7:15 AM
  • Hi Nouvel,

    Thanks for posting in the MSDN Forum.

    It's based on my experience that you need use Win32 API to find the correct window then modify the caption.

    Have a good day,

    Tom


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

    Monday, May 21, 2012 7:35 AM
    Moderator
  • Hi NR

    I'm guessing that, if it's possible to change the message in the "Warning", then it would have to be done via the IT interface, rather than the APIs. You could try asking in the TechNet forum set, where they generally know about configuration, the Office Resource Kit and Registry entries.

    Obviously, this is a security measure. Programmatic access through the APIs to change security things isn't usual, as that would defeat their purpose. Something like this, if it's possible at all, has to come from the IT side.

    If you have an Add-in running in the application, I'd think it would be possible to show a message elsewhere, in a custom task pane or the Ribbon, for example, when the document is opened.

    the other approach would be to make sure the document is signed or located in a trusted folder, thus avoiding the message entirely. Again, that's something that has to be done at the IT level.


    Cindy Meister, VSTO/Word MVP


    Monday, May 21, 2012 8:14 AM
    Moderator
  • Hi Cindy, thank you for your answer - but it is not an IT issue: the object model allows me to use ProtectedViewWindows.Open(), so I use it, for special case - I don't want to interfere with the regular messages, just change the message when my add-in use ProtectedViewWindows.Open(). Actually I could display another message elsewhere (I tried window.Caption) but the yellow bar is so apparent that most of users will basically read it and give it more credits / weight than any custom message.
    Monday, May 21, 2012 9:19 AM
  • Hi NR

    It's a matter of point-of-view. Theoretically, your software could be "bad" and you want to tell the user that your document is safe (when theoretically, it is not) and he should open it. As the user will trust the messages in this bar, allowing the developer to access it freely would not be the right thing to do. But letting IT access it would be placing the decision in the hands of "the bosses". Again, I don't know whether it's possible for IT, but if it is, then that's where you'd have to ask.

    The Microsoft software security philosophy goes something like this:

    The standard interface provided locks out "bad" things. We give the user (and IT) options to enable potentially "bad" things, but if the decision is made to do so, we are not at fault. So if the user decides to enable macros to run, or trusts a digital signature, or clicks "Enable", that's the user's decision. And the warnings about doing so have to be "guaranteed". So the anyone who may provide something "bad" will not be given access to the built-in warnings. You may not agree, but that's how it is.


    Cindy Meister, VSTO/Word MVP

    Monday, May 21, 2012 9:37 AM
    Moderator
  • Agree, except that my code is already trusted (and the proof is, it is already running :), AND in this scenario, I am the one who decides to use ProtectedViewWindows.Open - precisely to warn the user that she should not modify the document unless she really knows what she is doing.

    So far, using ProtectedViewWindows.Open seemed a good idea, but the issue is that the default message is kind of misleading in my case (at least, it's not specific enough) and the inability to set a different message is killing the whole scenario...

    My true point of view is, I'm wondering which scenario can use ProtectedViewWindows.Open (more secure - as compared to Documents.Open, less secure) and be satisfied with the default message. But that's another story.
    Monday, May 21, 2012 1:07 PM
  • Hi Tom, thank you for your answer - unfortunately in this case, the window's caption doesn't seem to be changeable - probably for security reasons.
    Monday, May 21, 2012 1:09 PM
  • Hi T.X., and thank you for your answer.

    Sounded promising, but that particular commandbar doesn't seem to be exposed through Office API...

    Monday, May 21, 2012 1:11 PM
  • Hi Nr,

    Hmmm, I will consult it in the internal channel. Let's see whether some experts can provide some workround here. It might be some time delay, thanks for you patience.

    Have a good day,

    Tom


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

    Tuesday, May 22, 2012 5:55 AM
    Moderator
  • <<I am the one who decides to use ProtectedViewWindows.Open - precisely to warn the user that she should not modify the document unless she really knows what she is doing.>>

    Ah, not exactly what the designers intended how the feature should be used (which explains why they don't give you the option) :-) But I follow your reasoning!

    <<My true point of view is, I'm wondering which scenario can use ProtectedViewWindows.Open (more secure - as compared to Documents.Open, less secure) and be satisfied with the default message. But that's another story.>>

    Actually, it's probably THE story... My inclination would be to put some kind of (possibly password) protection on the document. Either for editing, as a form, for comments or for review - depends on what you want to allow. Provide a message in a task pane - that's "in your face" - with a button for removing the protection.


    Cindy Meister, VSTO/Word MVP

    Wednesday, May 23, 2012 2:28 PM
    Moderator
  • @Cindy,

    About the scenario you mention:

    <<My inclination would be to put some kind of (possibly password) protection on the document. Either for editing, as a form, for comments or for review - depends on what you want to allow. Provide a message in a task pane - that's "in your face" - with a button for removing the protection.>>

    Password protection is another subject. It doesn't behave like (nor uses) the ProtectedViewWindows. If you set a protection for editing the document, nothing will prevent the user from actually editing the content, but she will just get notified in the end that she can't save it. If you use ProtectedViewWindows and cancel editing, then the user can't edit the content.

    So I still can't think of what the designers intended how the ProtectedViewWindows.Open feature should be used.

    @Tom, thank you for your answer - please update us when you have some news from the internal channel.

    Thanks to both of you.

    - NR

    Wednesday, May 23, 2012 4:03 PM
  • Hi Nr

    <<Password protection is another subject. It doesn't behave like (nor uses) the ProtectedViewWindows. If you set a protection for editing the document, nothing will prevent the user from actually editing the content, but she will just get notified in the end that she can't save it. If you use ProtectedViewWindows and cancel editing, then the user can't edit the content. >>

    Ah, we're thinking about different things, here :-) You're talking about password protecting the file as read-only. I'm talking about protecting the content of the document.

    go to the Developer tab; you should see a "Protect" group. Click the second button in the group to open the "Restrictions" task pane. (Forgive the awkward wording, I only have a German UI in front of me for 2010.) In the second section there's a drop-down list for different types of content protection. You might want to investigate these; I suspect that at least one would cover most of your concerns.

    Protecting for comments means the user can only add comments to the document, but can't change the content.

    Protecting for track changes (revisions) means any changes the user makes will be marked as revisions, but not integrated.

    Protecting as a form will block all work with the entire document, except for typing in form fields. If there are none present, then nothing can be done in the document, nor can anything be selected.

    "Read-only" means just that, except for any ranges that have been selected and explicitly made free for editing.

    <<So I still can't think of what the designers intended how the ProtectedViewWindows.Open feature should be used.>>

    This is intended as a automatic security measure. When the user opens a document from an "untrusted source" (such as a network location, Internet, email...) Word automatically "sandboxes" it so that nothing "bad" can execute. The user is duly warned and makes his own decision whether to take it out of the sandbox.


    Cindy Meister, VSTO/Word MVP

    Wednesday, May 23, 2012 4:14 PM
    Moderator
  • @Cindy, very good point, thank you for your suggestion - I would never have imagined that protecting as a form would be stronger than setting the file as readonly, but now I get the difference between protecting the file and protecting the content. This is a very good solution indeed, thanks for pointing to it.

    However it has a couple of drawbacks that could have made ProtectedViewWindows.Open a better fit:

    1) Changing the protection requires to edit and save the document, while switching from protected mode to normal mode and vice versa is just a matter of reopening the doc, not changing it (even programmatically).

    2) ProtectedViewWindows.Open is also available in PowerPoint and Excel, while Protect is not available in PowerPoint (it is in Excel though).

    Wednesday, May 23, 2012 5:11 PM
  • Hi NR

    All your points are valid. As I mentioned previously, once you described your scenario I understood why you wanted to use the feature. The problem is that Microsoft didn't design it with the use in mind to which you want to put it :-)

    If you were discussing this with a MS product manager (or similar) they might suggest that the "right way" would be to open the file originally in an Office viewer, then in the Office application. Of course, the problem with this approach is that there's no way to customize the UI of an Office viewer: You'd have to provide an extraneous UI for the user to say "I want to edit it".

    OTOH, I imagine it should be possible to use the Windows API to anchor a smallish Form at the side of the viewer window to provide the message and the button...


    Cindy Meister, VSTO/Word MVP

    Thursday, May 24, 2012 7:56 AM
    Moderator
  • @Cindy:

    I am trying the Protect approach, but if I set Protect to read-only, and then try to set it to NoProtection when the user clics on the button, it just stays protected. Any clue?

    Thanks in advance,

    - NR

    Friday, May 25, 2012 7:34 AM
  • Hi NR

    Use the Unprotect method :-)


    Cindy Meister, VSTO/Word MVP

    • Marked as answer by nouvel-r Friday, May 25, 2012 4:25 PM
    Friday, May 25, 2012 4:16 PM
    Moderator
  • Many thanks Cindy, I had missed it.

    Sometimes I wish I lived in a world where Protect(NoProtection) == Unprotect(), but...

    Friday, May 25, 2012 4:31 PM