none
How to know the Office trial license expiration date in an Excel addin ?

    Question

  • Hi all,
    I'm writing an Excel 2007 addin in C#.
    In the initialization, i want to test if the license of office is a trial one and if this license has expired.

    I got the following exception:
    "This command cannot be used as the license to use this application has been expired"

    I appreciate any help anyone may be able to give.

    Thanks

    Friday, August 14, 2009 3:30 PM

All replies

  • Hello ,

    I've tried to find some more information about the error message you gave, but I failed, is this a translated message?
    Would you please provide some code snippet which covers the command that cause this expection?

    As far as I know the Office Object Model doens't provide any methdo to retrieve this kind of information, but we could find the license type in registry, pelase refer to this hive:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration\



    Thanks
    We have published a VSTO FAQ recently, you can view them from the entry thread VSTO FAQ.
    If you have any feedbacks or suggestions on this FAQ, please feel free to write us emails to colbertz@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, August 19, 2009 7:33 AM
  • Hi,
    Thank you for your anser.
    About the message, you are right, the message that i had comes from a japanase translated error message.
    So finally I got the english error message which is: 'This command is unavailable because the license to use this application has expired'

    Here is some code to get the exception
    Suppose that you access to the Excel application with Application variable.
    In your addin initialization, add
         Application.WorkbookOpen += AppEvents_WorkbookOpenEventHandler(OnWorkbookOpen);

    private void OnWorkbookOpen(Microsoft.Office.Interop.Excel.Workbook wb) {
        bool oldDisplayAlerts = Application.DisplayAlerts;
        try {
             Application.DisplayAlerts = false;
             Application.DisplayAlerts = oldDisplayAlerts;
        } catch (Exception e) {
             string msg = e.Message;
        }
    }


    Once you open a workbook with the command Open, you have the exception. Note that you don't it if you double-click on an .xlsx file.

    So is there a solution during my addin initialization to test if the license is correct so that I can deactivate all my commands?

    Thanks for you help.
    Pascal.

    Wednesday, August 19, 2009 2:26 PM
  • Hello,

    As my last post, we could check the information in registry when your add-in starting up.
    Or we could work this around without check the license, just use try catch block as you already did to handle the exception.

    Thanks
    We have published a VSTO FAQ recently, you can view them from the entry thread VSTO FAQ.
    If you have any feedbacks or suggestions on this FAQ, please feel free to write us emails to colbertz@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, August 20, 2009 2:37 AM
  • Hi,
    About the registries, I have some questions:
    - Could you give me more information about which keys that I can check ? Because, I saw that there are entries such that LicenseType, TrialType but I don't which values are for Trial version of Office.
    - And as there are multiple entries in Registration, how can I get the key for the activated office?
    - And last question, how can I know if the trial period has expired (which is what I want to know)?

    About the exception that is catched when a workbook is open, as I said it doesn't work when I double-click on an Excel document because the license checking has not yet been done. So I think that I can't use that bacause it doesn't work for all scenarios.

    Thanks for your help.
    Pascal.
    Thursday, August 20, 2009 9:01 AM
  • Hi,
    About my second question, I found the answer.
    There is the property ProductCode on the application which gives us the entry in the registry.
    But do you have any information about the two others question?
    Thanks
    Pascal.
    Tuesday, August 25, 2009 12:54 PM