none
How to get error code or Exception for password protected Power point document? Office Automation using C++ RRS feed

  • Question

  • Hi,
    • I am using C++ office automation to open word, excel and power point documents and getting error codes (800A1520 for word and 800A03EC for excel)  if i try to open a password protected word and excel document.
    • However, if I try to open a password protected power point document I am getting error code as '-2147352567 (80020009)' which is I suppose not due to password protected document but because of incorrect parameters.
    • I am passing following parameters to open password protected power point-> file path (string), read only (true), untitled(false) and withwindow  (true).
    • I suppose that i need to pass more parameters the way i have passed to Open a word and excel document.
    • I have taken reference from: http://engine.keeboo.com/admin/KeeBookCreator.txt
    • HRESULT TWordConverter::OnOpen(LPDISPATCH pDisp, VARIANT* pResult)
    • I have also went through following links:
    • http://support.microsoft.com/default.aspx?scid=kb;en-us;257757
    • http://support.microsoft.com/kb/310744/en-us
    • I was unable to find any explanation for power point.

    Can anybody help me know the exact number and type of parameters i need to pass for getting error exception/code while opening password protected power point document. 

    Thanks,

    Varsha

    Tuesday, December 24, 2013 11:57 AM

All replies

  • Hello Varsha,

    What code do you use for opening a PowerPoint file?

    Note, you can open *.pptx files extracting their content as a regular *.zip folder. Open XML SDK can be used for such tasks.

    Please take a look at the similar forum thread How to open a password protected .ppt file with the Microsoft.Office.Interop.PowerPoint .

    Tuesday, December 24, 2013 1:51 PM
  • Hi Eugene,

    I am using following code to open PowerPoint file.

    // Flags: ReadOnly,Untitled,WithWindow        m_hr = RS_Invoke(docs.pdispVal,L"Open",DISPATCH_METHOD,&doc,4,CComVariant(szPath),                        CComVariant(1),CComVariant(0),CComVariant(1));

    I have used following code to open word files and I get error code "800A1520" when i try to open a password protected word file. Based on this error code I am able to handle the password protected files.

    I am also setting "DisplayAlerts" to false to suppress all the alerts.

              m_hr = RS_Invoke(docs.pdispVal,L"Open",DISPATCH_METHOD,&doc,9,CComVariant(szPath),				 CComVariant(0),CComVariant(1),CComVariant(0), 				 CComVariant(L"39819af"), CComVariant(L"39819af"), 				 CComVariant(0),				 CComVariant(L"39819af"), CComVariant(L"39819af"));

    I tried using two calls to open password protected PowerPoint (as mentioned in link provided by you), however it is not working !!



    Tuesday, December 31, 2013 5:08 AM
  • Hello Varsha,

    Did you try to use the Open method of the ProtectedViewWindows class right after the Open method of the Presentations class fails?

    The forum thread I mentioned in my previous message provides the following code:

    Presentations presentations = powerPoint.Presentations;
    Thread openPPT = new Thread(delegate() {
       presentations.Open("filepath", MsoTriState.msoTrue, MsoTriState.msoFalse);
    });
    
    openPPT.start();
    if (!openPPT.Join(20000)) // 20 seconds to open
       throw new Exception("Can't open, took too long, 
       //probably requires password...etc...etc.");
    else
       // processfile.... 
    
    // try/catch around the open to catch the 'invalid password' issue if you want... use  powerPoint.ProtectedViewWindows.Open with a fake password and it will throw it there...
    
    // other options include:
    
    ps = powerPoint.ProtectedViewWindows.Open(request.FilePath, "fakePassword", Microsoft.Office.Core.MsoTriState.msoFalse).Presentation;                            
    if (!string.IsNullOrEmpty(ps.PasswordEncryptionAlgorithm))
    {
       throw new Exception("PowerPoint file requires a password, this cannot convert.");
    }
    
    If the Open mehtod of the Presentations class fails, you can use the Open method of the ProtectedViewWindows class for opening password protected files.
    Tuesday, December 31, 2013 2:47 PM
  • Hi Eugene,

    My code is in C++ and I am not using any direct API's. I am using following code to open a password protected documents. So I am unable to use Open method of the ProtectedViewWindows class for opening password protected files.

     

    My code:

    CComDispatchDriver        lDocumentsDriver(pDisp);
    CComVariant                       
     lOpenResult;
    HRESULT                           
     lResult;
    // The following call is supported by PowerPoint 97, 2000 and plus...
    {
       CComVariant varArgs_param1(m_From);                      
     // FileName
       CComVariant varArgs_param2(true);                        
     // ReadOnly
       CComVariant varArgs_param3(false);                       
     // Untitled
       CComVariant varArgs_param4(false);              
     // WithWindow
                    
    
    CComVariant varArgs[4] =  {varArgs_param4,varArgs_param3,varArgs_param2,varArgs_param1};
    
    long lDispId_Documents_Open;
    
    lResult = lDocumentsDriver.GetIDOfName(L"Open", &lDispId_Documents_Open);
    
                     if (SUCCEEDED(lResult))
                     {
                             
     EXCEPINFO pExcepInfo;
                             
     unsigned int puArgErr = 0;
                             
     DISPPARAMS dispparams = { &varArgs[0], NULL, 4, 0 };
                       lResult = ((IDispatch *)lDocumentsDriver)->Invoke(    
    
                                           
     lDispId_Documents_Open,    
                                           
     IID_NULL, LOCALE_USER_DEFAULT,       
                                            DISPATCH_METHOD,&dispparams,
                                           
     &lOpenResult,&pExcepInfo,&puArgErr);
    
                             
     if (SUCCEEDED(lResult) && (lOpenResult.vt == VT_DISPATCH))
                             
     {
                                      
     lOpenResult.Detach(pResult);
                             
     }
                     }
      }

     

    Reference: http://engine.keeboo.com/admin/KeeBookCreator.txt . I am using OnOpen methods for excel and word from this link and it just works fine for non-password and password protected documents.

    By taking reference from forum thread I tried varying the parameter list/values we are passing to varArgs. For non- password and password protected PowerPoint Invoke method is returning same error code and hence I am not able to view non-password protected PowerPoint. For some ppt is works for other it doesn’t work.

    I have tried following combinations for parameters:

       // Flags: ReadOnly,Untitled,WithWindow

     CComVariant varArgs[4] =    {“filePath”, CComVariant(1), CComVariant(0) , CComVariant(0)};

     CComVariant varArgs[4] =    {“filePath”, CComVariant(1), CComVariant(1) , CComVariant(0)}

       CComVariant varArgs[4] =    {“filePath”, CComVariant(1), CComVariant(0) , CComVariant(1)};

       

    CComVariant varArgs[4] =    {“filePath”, CComVariant(1), CComVariant(1) , CComVariant(1)};

       CComVariant varArgs[4] =    {“filePath”, CComVariant(1), CComVariant(0)}; and second call with    CComVariant varArgs[4] =    {“filePath”, “defaultpassword”, CComVariant(0)};

     

    As per two lasts posts in forum looks like workaround/trick to handle password protected file by calling "Open" twice is failing for non-password protected document.



    Wednesday, January 1, 2014 11:05 AM
  • Hi Varsha,

    Do you still use PowerPoint 97 or 2000 as noted in the code? Why can't you use the Open method of the ProtectedViewWindows class? Note, the classes was introduced with PowerPoint 2010. The http://officeone.mvps.org/openppt/ page states the following regarding earlier versions of PowerPoint:

    The previous versions of Microsoft PowerPoint do not allow you to supply a password through VBA/Automation when opening a password-protected presentation file.

    Also I have found a similar forum thread which provides another workaround.

    Of course, you can try to contact Microsoft regarding the issue you faced with. There are differences in how you'd file a bug report/support incident depending on whether or not you have an MSDN subscription with incidents, or you're a premier partner, etc. But I suppose it is useless.

    Wednesday, January 1, 2014 5:17 PM