Launch Conditions for Dropbox / Office 2013 Plugin - Advanced Installer Community
Codplay
Posts: 3
Joined: Sat Dec 21, 2013 9:35 am

Launch Conditions for Dropbox / Office 2013 Plugin

I am attempting to build an installer for a small tweak that requires Office 2013 (or 365) as well as Dropbox to be installed. The installer then needs to determine the Dropbox folder (in case the user has customized it) and check to see if the user has logged into an account within Office. Checking for the Dropbox installation is easy (just check for HKCU\Software\Dropbox :lol: ) but the rest gets a little complicated.

First - Office version. I want to check for the presence of any Office 2013 or 365 application, not just Word or Excel specifically. I was planning to do this through checking for the value ProductVersion at HKLM\SOFTWARE\Microsoft\Office\15.0\Common\ or HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\
However, according to this technet thread, it seems that the issue isn't quite that simple once you throw 365 into the mix. They suggest that the best way to detect the presence of Office is through the progIDs (Excel.Application.15, Word.Application.15, etc). Given that, would it be sufficient to search for the keys HKLM\Software\Classes\Excel.Application.15 OR HKLM\Software\Classes\Word.Application.15 OR HKLM\Software\Classes\Powerpoint.Application.15 to meet my criteria (both 2013 and 365 seem to use the version 15) or is there a better way to go about this?

Secondly, checking for the connected account within Office. This part is relatively simple - I believe I just have to search for the value ConnectedAccountCID at HKCU\Software\Microsoft\Office\15.0\Common\Identity and verify that it is not NULL. However, if it is NULL, I don't want the installer to fail - just return a message saying that the user will have to log into an account within office before the modifications will take effect. Is this possible?

Lastly, I need to determine the Dropbox install location, and then keep that string so I can write a custom registry value later. By default, Dropbox installs to %HOMEPATH%\Dropbox, but this can be customized. The location is actually stored in an base64 encrypted file at %APPDATA%\Dropbox\host.db in the second line. From stackoverflow and a dropbox dev there is a lovely piece of C# that extracts this information, but I'm unsure of how I can integrate this. The code is:

Code: Select all

 private static string GetDropBoxPath()
    {
        var appDataPath = Environment.GetFolderPath(
                                           Environment.SpecialFolder.ApplicationData);
        var dbPath = Path.Combine(appDataPath, "Dropbox\\host.db");

        if (!File.Exists(dbPath))
            return null;

        var lines = File.ReadAllLines(dbPath);
        var dbBase64Text = Convert.FromBase64String(lines[1]);
        var folderPath = System.Text.Encoding.UTF8.GetString(dbBase64Text);

        return folderPath;
    }
This doesn't fall under a launch condition as such, and I'm completely lost as to whether or not this is even possible with your software. I'm certainly not looking to use the Dropbox API in any way, as I'm not reading or writing anything to the Dropbox folder - I just need to know where it is!

Hopefully this can be done - I've only ever done web programming, and don't really have the knowledge to write and compile my own installer executable (even though it's only making a few registry changes!) The whole thing can otherwise be run through a bat file (and has been up to this point), but I'd really like to streamline it and make things dummy proof.

Cheers,

-Philip
Codplay
Posts: 3
Joined: Sat Dec 21, 2013 9:35 am

Re: Launch Conditions for Dropbox / Office 2013 Plugin

Oops - I seem to have posted this in the wrong forum. :? That's what I get for posting so late at night!! If a mod could move it to the Building Installers section that would be great. Thanks!
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Launch Conditions for Dropbox / Office 2013 Plugin

Hi Philip and welcome to Advanced Installer forums.
First - Office version. I want to check for the presence of any Office 2013 or 365 application, not just Word or Excel specifically. I was planning to do this through checking for the value ProductVersion at HKLM\SOFTWARE\Microsoft\Office\15.0\Common\ or HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\
However, according to this technet thread, it seems that the issue isn't quite that simple once you throw 365 into the mix. They suggest that the best way to detect the presence of Office is through the progIDs (Excel.Application.15, Word.Application.15, etc). Given that, would it be sufficient to search for the keys HKLM\Software\Classes\Excel.Application.15 OR HKLM\Software\Classes\Word.Application.15 OR HKLM\Software\Classes\Powerpoint.Application.15 to meet my criteria (both 2013 and 365 seem to use the version 15) or is there a better way to go about this?
If you want to determine if all the Office 2013 application are installed on the user's machine, you can create a search for each application and then use them all in the Launch Condition page, "Custom" tab.
Secondly, checking for the connected account within Office. This part is relatively simple - I believe I just have to search for the value ConnectedAccountCID at HKCU\Software\Microsoft\Office\15.0\Common\Identity and verify that it is not NULL. However, if it is NULL, I don't want the installer to fail - just return a message saying that the user will have to log into an account within office before the modifications will take effect. Is this possible?
In order to achieve this you can go in the Custom Actions page, add a "Display message box" predefined custom action and use the search property as a condition for it.
Lastly, I need to determine the Dropbox install location, and then keep that string so I can write a custom registry value later. By default, Dropbox installs to %HOMEPATH%\Dropbox, but this can be customized. The location is actually stored in an base64 encrypted file at %APPDATA%\Dropbox\host.db in the second line. From stackoverflow and a dropbox dev there is a lovely piece of C# that extracts this information, but I'm unsure of how I can integrate this.
In order to use the C# code in Advanced Installer you can create a custom action like described in the How do I create fully fledged C# custom actions article, the go in the Custom Actions page and add the resulted DLL using the Call function from attached native DLL predefined custom action.

Your custom action should store the result (Dropbox location) in a property which you will use when you want to write the custom registry value.

Let us know if this helped, otherwise give us more details about your scenario.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Codplay
Posts: 3
Joined: Sat Dec 21, 2013 9:35 am

Re: Launch Conditions for Dropbox / Office 2013 Plugin

Hi Eusebiu,

Thanks so much for the help! Got me most of the way there. Everything is now working smoothly apart from the manual scripting.

I noticed there was an Execute Inline Script in VB in the Custom Actions menu, so I put this code there but it doesn't seem to be running...

Code: Select all

Imports System.IO
Module GetDropbox
    Private Function GetDropBoxPath() As String
        Dim appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
        Dim dbPath = Path.Combine(appDataPath, "Dropbox\host.db")
        If Not File.Exists(dbPath) Then
            Return Nothing
        End If
        Dim lines = File.ReadAllLines(dbPath)
        Dim dbBase64Text = Convert.FromBase64String(lines(1))
        Dim folderPath = System.Text.Encoding.UTF8.GetString(dbBase64Text)
        Return folderPath
    End Function
    Sub main()
        ' Console.WriteLine(GetDropBoxPath)
        ' My.Computer.Registry.CurrentUser.CreateSubKey("SOFTWARE\Microsoft\Office\Common\Cloud Storage\2c0ed794-6d21-4c07-9fdb-f076662715ad")
        My.Computer.Registry.SetValue("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\Common\Cloud Storage\2c0ed794-6d21-4c07-9fdb-f076662715ad", "LocalFolderRoot", GetDropBoxPath)
    End Sub
End Module
I know the code is good, because it runs perfectly in VisualStudio. I believe I'm just missing something important... :oops: Only ever written web (PHP) code before!! Is it maybe that I wrote .NET code by mistake and AI doesn't support .NET?

Cheers! (And happy new year!)

-Philip
Eusebiu
Posts: 4971
Joined: Wed Nov 14, 2012 2:04 pm

Re: Launch Conditions for Dropbox / Office 2013 Plugin

Hi Philip,
Is it maybe that I wrote .NET code by mistake and AI doesn't support .NET?
Indeed, it seems that you used .NET code in your script (i.e. "Imports System.IO", "Environment.GetFolderPath" method), but the Execute inline script custom action type only supports VBScript or JScript code.

To achieve what you want you can either create a fully C# custom action as described in the How do I create fully fledged C# custom actions article or create a fully VBS custom action.

Best Regards and Happy New Year,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”