Determining Total Ram for a prerequisite install condition - Advanced Installer Community
dms
Posts: 164
Joined: Tue Aug 28, 2007 7:11 am
Location: UK

Determining Total Ram for a prerequisite install condition

Hi
Following Dan's suggestion on the Feature requests forum I have a simple Custom executable to determine the Total amount of Ram on a target machine;

Code: Select all

Module Module1

    Sub Main()
        GetRamAmount()
    End Sub
    Public Function GetRamAmount() As Integer
        Dim mem As Long = CLng(New Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory)
        If mem > 50000000 Then
            Return 0
        Else
            Return 1
        End If
    End Function

End Module
I can then set up a search install condition based on this executable. I want to determine whether to install the 64 bit version of sql express on a 64 bit operating system if it is a) not present in the first place and b) there is more than 4 gb of ram on the machine (this does mean that the actual condition in the code will need to be set correctly but it suffices for the example here). In reality in order to fulfil the install conditions (ie both fail so installation will occur should I be returning 1 if the total ram is greater than 4 gb and 0 if it isn't?

Actually I think in reality that I should return 1 in the first path ensuring failure and hence installation. This does beg one more question though if I may, Are pre requisites evaluated (and installed)in the order in which they are added to the pre requisites page. So in my case if I want to condition the installation of 64 bit sql that should be looked at first, and if that fails to install then it will fall back to the 32 bit version (which I would also have as a prerequisite).

Dom
Dan
Posts: 4530
Joined: Wed Apr 24, 2013 3:51 pm

Re: Determining Total Ram for a prerequisite install conditi

Hi Dom,

You can enable the Install only if all conditions are false option from the Prerequisite Install Conditions Tab. If this option is selected, all searches must fail in order to install the prerequisite.

So, you can return value 1 when you detect that more than 4GB of RAM are installed on the target machine otherwise return value 0.
That means for the target machines which have more than 4GB of RAM installed the value will be interpreted as failure which is what you need, you want the related prerequisite to be installed.

So, your code should look something like that:

Code: Select all

Module Module1

    Sub Main()
        GetRamAmount()
    End Sub
    Public Function GetRamAmount() As Integer
        Dim mem As Long = CLng(New Microsoft.VisualBasic.Devices.ComputerInfo().TotalPhysicalMemory)
        If mem > 50000000 Then
            Return 1
        Else
            Return 0
        End If
    End Function

End Module
Please let me know if that works as expected.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”