by Sameera 5/21/2008 2:28:00 AM

Detecting and Deploying Prerequisites

This is the 2nd of a multi-part series on deploying VSTO Applications using NSIS. Part 1 of the series can be found here.

Step 4: Ensuring MSI 3.1 is available

Before proceeding you need to make sure the client computer has MSI 3.1 installed. Click here to find out how.

Step 5: Checking whether Excel is Installed

Being an Excel Worksheet-Level Customization, it makes no sense for this app to be deployed on a computer that doesn't have MSO Excel 2003 Professional installed. Lets see how we can achieve this. If you do a bit of research you can find out that with VS Deployment Projects, this is achieved by doing a Windows Installer search for the component ID {A2B280D4-20FB-4720-99F7-40C09FBCE10A}.

Since performing a Windows Installer Search is a common and desirable feature, I came up with the following macro:

!macro GenerateMsiSearch functionName componentId
    Function ${functionName}
        Push $0
        Push $1
        StrCpy $0 ""
        StrCpy $1 ""
        System::Call "msi::MsiLocateComponent(t '${componentId}', t, *i) i .r1"
        DetailPrint "Component ID: ${componentId} Install State: $1"
        ${If} $1 == '3' ; installed on local drive
            StrCpy $0 '1'
        ${ElseIf} $1 == '4' ; run from source, CD or net
            StrCpy $0 '1'
        ${ElseIf} $1 == '-3' ; Path  to the component returned more data than our buffer can handle. Which means we do have this installed.
        ${Else}
            StrCpy $0 '0'
        ${EndIf}
        Pop $1
        Exch $0
    FunctionEnd
!macroend

When invoked, this macro will generate a function, with the give name that will search for the specified Component ID. So the code to detect Excel 2003 becomes:

!insertmacro GenerateMsiSearch "IsExcelInstalled" "{A2B280D4-20FB-4720-99F7-40C09FBCE10A}" ; Version 2003

Section "MainSection" SEC01
    ; Determine whether the user has the required version of Excel installed
    Call IsExcelInstalled
    Pop $0
    ${If} $0 == '0'
        MessageBox MB_OK "A compatible version of Microsoft Office Excel was not found. Setup cannot continue."
        Abort
    ${EndIf}

[/code]

So, why did I make this a macro that generates a function, and not just a function that accepts the component ID as a parameter? Well, parameter passing is not that straight forward with NSIS, and I believe this leads to much cleaner code at the end.

Step 6: Ensuring .NET 2.0 Runtime is Present

You can find plenty of ways to do this on NSIS web site. Here's one of them.

Step 7: Ensuring VSTO is Present

!insertmacro GenerateMsiSearch "IsVstoInstalled" "{D2AC2FF1-6F93-40D1-8C0F-0E135956A2DA}"

Function InstallVSTOSE
    ; ${DirState} '$COMMONFILES\Microsoft Shared\VSTO\8.0' $1
    Call IsVstoInstalled
    Pop $0
    ${If} $0 == '0'
        SetOutPath '$TEMP'
        SetOverwrite on
        Banner::show /NOUNLOAD "Microsoft VSTO SE..."
        File 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\vstor\vstor.exe'
        ExecWait '$TEMP\vstor.exe /q:a /c:"install"' $1 ; '$TEMP\vstor.exe /q:a /c:"install /q"' $1
        Delete '$TEMP\vstor.exe'
        Banner::destroy
        ${If} $1 == '0'
            DetailPrint "VSTO 2005 SE was installed successfully."
        ${ElseIf} $0 == '3010'
            SetRebootFlag true
        ${Else}
            DetailPrint 'VSTO 2005 SE Installation failed with error $1'
            Abort
        ${EndIf}
    ${Else}
        DetailPrint 'VSTO 2005 SE already installed.'
    ${EndIf}
FunctionEnd

We now have the scripts in place to deploy the application components as well as the to determine all prerequisites are available. All that is left is to add the boiler place Update Manifest and Set Security code. Easiest way to do this is to bring the code over a new .NET EXE project and pass the installation-dependant (e.g. Installation Path etc.) parameters as command line arguments. You can then execute the EXE as the last step of the installation.

Related posts

Add comment


(Will show your Gravatar icon)  





Live preview

8/20/2008 7:07:44 AM

 By 

About the author
Sameera Perera Sameera Perera Feed
Code, art and a whole lot of attitude...

E-mail me Send mail

Calendar
<<  August 2008  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar
Recent comments
Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008

All forms of source code published on Codoxide.com and CodeOfDefiance.com are distributed under the Apache License, Version 2.0 unless otherwise stated.
The rest of the content are published under a Creative Commons Attribution 3.0 License.
Creative Commons License

Sign in


CodoxideTM
Powered by BlogEngine.NET 1.2.0.0