Geeks With Blogs
Neil Smith [blog]code til ur fingers bleed

Sent Sage £1500 and got 4 cds and a thank you letter in return, nice.  This entitles me to use their development SDK for a whole year so the sooner I get my programs linking to it the better.  I've decided the best approach will be a windows service which runs on one machine and polls a folder every x minutes and reads in xml documents which my various programs will create.  Given that the Sage SDK is actually an ActiveX class library at the time of writing called SdoEng120.dll, this service is going to pass the xml document to a vb.net dll which will also contain the sagev12 version number in its filename in an attempt to avoid future dll hell, parse the document and create customers/suppliers/invoices/credit notes/etc.

Not all of my customers are going to have the sage link, so I needed a mechanism for working out whether my service was installed and running.  This applications current installers are all created within vs2005 as Setup & Deployment projects and i've been trying to find a way of working out in code whether or not a .net assembly is installed on this machine regardless of whether it was installed with 'Just Me' or 'All Users'.  The registry keys seem wildly different between the two options unless you know the guid assigned to the setup project on creation by Visual Studio as its ‘ProductCode’ which I didn’t want to assume, I wanted it to work by name, so I could ask something like :-

IsDotNetAssemblyInstalled(“My Sage Link”)

Where the “My Sage Link” part was what actually appeared in Control Panels’ Add/Remove Programs applet.  There is very little information to be found on the web.  I suspect largely because products like Wise and InstallShield exist,  Installshield being my usual first choice.

I have often thought it strange why the Add/Remove Programs applet takes so long to show you what’s installed, I thought it just had to read a few registry keys from one place and display the list, it’s a bit more complex than that.  Here’s the code…

private bool IsDotNetAssemblyInstalled(string sIn)

{

    try

    {

            string sDN = "";

            string sRegKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            RegistryKey rk = Registry.LocalMachine.OpenSubKey(sRegKey);

            string[] keys = rk.GetSubKeyNames();

            foreach (string key in keys)

            {

                sDN = GetRegistryDisplayNameSubKey(sRegKey + @"\" + key);

                if (sDN == sIn)

                        return true;

            }

            return false;

    }

    catch (Exception ex)

    {

            LogException("IsDotNetAsssemblyInstalled", ex.ToString());

            return false;

    }

}

private string GetRegistryDisplayNameSubKey(string sIn)

{

    try

    {

            RegistryKey r = Registry.LocalMachine.OpenSubKey(sIn);

            return r.GetValue("DisplayName").ToString();

    }

    catch

    {

            return "";

    }

}

private void LogException(string sWhere, string sIn)

{

    StreamWriter sw = new StreamWriter(DateTime.Now.ToString("ddMMyyyyhhmmss") + ".txt");

    sw.Write(sWhere + Environment.NewLine + sIn);

    sw.Close();

}

Posted on Friday, June 2, 2006 10:49 AM | Back to top


Comments on this post: Is an assembly installed???

# re: Is an assembly installed???
Requesting Gravatar...
File SDOEng120.dll is on the retail CD provided by Sage.

Look in /Line50/Disk1/Data1.cab - WinZip will extract this file.

Now, a question to you: where can I find file SDOEng120.tlb?

Good luck.
Left by Brian Watson on Oct 14, 2006 8:01 AM

Your comment:
 (will show your gravatar)


Copyright © Neil Smith | Powered by: GeeksWithBlogs.net