locked
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM keeps resetting RRS feed

  • Question

  • Hey all,

    I have some C# code which:
    1) opens up a Word document
    2) changes HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM to 1 to allow macro code to be inserted and run

    and then when the user closes the document it changes HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM back to 0 (zero).

    I can see this because if I refresh the value in the registry while tracing the code line by line, it's set to zero.

    But, once the C# debug completes (I hit F10 the whole way through) and application returns to the front so it's the main app again, the value for HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM gets set back to 1!

    There's no value under HKEY_CURRENT_MACHINE\Software\Microsoft\Office\11.0\Word\Security\AccessVBOM, so it can't be that.

    Does anyone have any ideas what might be causing this?

    Thanks!
    Tuesday, October 28, 2008 4:05 AM

Answers

  • It's been brought to our attention that apparently there's a known issue with this, so we have to make the code a little less glamorous to work (do all sorts of registry key insertions/deletions elsewhere, which we now have working).

    Thanks everyone.
    • Marked as answer by FireMyst Wednesday, October 29, 2008 2:40 AM
    Wednesday, October 29, 2008 2:40 AM

All replies

  • Here's the code. The first part is the last of the code that calls the SetWordMacroSecurity(0); the second part is the method itself. 


    if (Continue)
         {
          _wordDoc.Saved = true; // We don't want the Save dialog to appear

                            // SCR3622 - Make sure we copy the latest version of the file to the server on
          //           close if we own the lock on the document.
          if (_ccf.DocumentLockedbyUs(Convert.ToInt32(_dcdata.ClientId), _dcdata.SaveDir, _dcdata.SeqNo))
          {
           SyncLocalwithServer();
          }

          RemoveConnection();

          try
          {
           WordDocumentClosed(this, ref Continue);
          }
          catch
          {
           // Event Handler has detached somehow ...
          }

          _wordDoc = null;
              
          _paramfalse = false;
          _paramOptional = Missing.Value;

                            if (_wordApp != null)
          {
           docCnt = _wordApp.Documents.Count;  //jb! i have moved this to here temporarily
           if (docCnt <= 1)
           {
            //_wordApp.Application.Options.SaveInterval = _intCurrentSaveDuration;

            //close the owner word application if this is the only document open
                                    _wordApp.Quit(ref _paramfalse, ref _paramOptional, ref _paramOptional);
                                }
          }

                            _wordApp = null;
         }

                //DL: Reset Word Macro security.
                SourceDocMgr.SetWordMacroSecurity(0);

    ////////// the above is the end of the code with the exception of all the curly braces. When I hit F10 in Visual Studio
    /////////  to go line-by-line, that's it.
    ////////// Before I hit F10 for the last time, I do a refresh in the system registry and see the value is still set to zero.
    ////////// When Word exits, and the main screen comes back, the registry says "1" again.
    /////////  below is the method I have called "SetMacroSecurity"


    private void SetWordMacroSecurity(int RegSetting)
      {
       try
       {
        //allow the VB project acccess to set the macro
        //HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Word\Security\AccessVBOM
                    //RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\10.0\Word\Security", true);
                    //DL CHANGE REGISTRY KEY FOR WORK FIXING UPON EXIT.
                    RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Office\11.0\Word\Security", true);
                    if (!_blnGotCurrentVBPSecurity)
        {
         //// get the value. If it doesn't exist, assign a default value of 0.
         _intCurrentVBPrjSecurity = (int)key.GetValue("AccessVBOM", 0);
         _blnGotCurrentVBPSecurity = true;
        }
        key.SetValue("AccessVBOM", RegSetting);
        key.Close();
       }
       catch
       {
        //ignore errors here
       }
      }

    Tuesday, October 28, 2008 6:33 AM
  • It's been brought to our attention that apparently there's a known issue with this, so we have to make the code a little less glamorous to work (do all sorts of registry key insertions/deletions elsewhere, which we now have working).

    Thanks everyone.
    • Marked as answer by FireMyst Wednesday, October 29, 2008 2:40 AM
    Wednesday, October 29, 2008 2:40 AM
  • on VBA i used On Error Resume Next to fix this issue.

    for C# maybe you can use try{...} catch{....}.

    Thursday, June 2, 2011 1:54 PM