Visual studio .NET integrated windows installer : self registering of a dll (vsdrfCOMSelfReg)

In my application I use SQLDMO to have acces to the same possibilities as in the SQL Enterprise Manager (sqldmo.dll)
My application must run on PC's with already MSDE/SQL Server installed or PC's without MSDE/SQL Server installed (even no installed SQL Client software).
Microsoft has a knowledge paper with the steps to follow what to install for being able to run SQLDMO on a client machine without SQL client software.
You must install several dlls and one dll (sqldmo.dll) must be registered.
In a windows installer project (Visual Studio .NET) you can set the proporty REGISTER of this dll to vsdrfCOMSelfReg.
After running my installer my application was running on all machines (it worked  :-) )
But there is a 'BUT' :
The installer is not detecting that the dll is already installed and registered on machines with SQL Server. It will overwrite the existing settings and if my application is removed, the Enterprise Manager for example will not work anymore because the sqldmo.dll is not registered anymore (the deinstaller removed the registering...)

How do I tell the installer to not register the dll if this dll is already registered. It must only register the dll on 'clean' machines.
I'v searched already the net for an answer, but no luck for the moment...
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What about installing all DLL's WITHOUT registrating them using a ProjectInstaller, then write some code in the 'AfterInstall' event to check whether that 1 dll is already registrated. If not: run regsvr32.exe to register it.

ericvbAuthor Commented:
Yes, I thought about it also, but how do I test if a dll is already registered?
Till now I didn't find a line of code in C# to test this.
I could also look manually in the registry, but is there no other way, using the .NET environment, for example?
I didn't find anything in the MSDN library, but I'm overlooking it maybe
I think (*know*) it can be done using some API's. But I don't have my api collection here.
I can take a look for you this evening it you want.
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

ericvbAuthor Commented:
I should be gratefully if you want to do this.
I know also that it must be possible, but I do not find it for the moment :-((
It drives me crazy, it looks so simple...
Ok, I looked for the api and I guess I was wrong. At least, I can't find it ;-)
However, I got another idea.

I am building a 'registry scanner' which scans for the dll.
Got it all working except for the last stage...the reading of the value.

Still working on it ;-)
Bob LearnedCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

PAQ with points refunded

Please leave any comments here within the next seven days.

EE Cleanup Volunteer
Woah, forgot on this one. Do you still need a scanner?
ericvbAuthor Commented:
Yes, of course  :-)
The problem is still there, I didn't find a solution.
I must admit, that I putted this problem aside, didn't have the time to put more time in it.
Ok, I've build it for a great part, I only need to finish it...
PAQed, with points refunded (200)

E-E Admin
Computer101, please read the last 2 comments. I was still working on this one!

ericvb, do you agree to open the question?
ericvbAuthor Commented:
I agree to let this question open
ericvb, it seems that C101 has forgotten about us.
I can reopen this question as well. Do you remember how many points you set on it? Then I can set it again.
eric, this is what I have so far.

I've build a recursive function which will scan for the registry key.
This works just fine and is even quit fast (depending on your computer of course).
However, I can NOT access the last value of a key. Didn't find that yet.
But posting this anyway, so you can try as well.

You need to import this:

Imports Microsoft.Win32.Registry

Then the function:

    Private Function SearchKey(ByVal strStart As String, ByVal strSearchFor As String) As String
            Dim ky As Microsoft.Win32.RegistryKey = CurrentUser.OpenSubKey(strStart, False)
            If ky Is Nothing Then Return ""
            Dim arr() As String = ky.GetSubKeyNames()
            Dim arrd() As String
            Dim arrValues() As String
            Dim strResult As String
            Dim kyval As Microsoft.Win32.RegistryKey
            Dim i As Int32 = 0
            If arr Is Nothing Then Return ""
            If arr.Length = 0 Then
                arr = ky.GetValueNames()
                If arr.Length > 0 Then
                    kyval = CurrentUser.GetValue(ky.Name)
                End If
            End If
            For Each strKeyName As String In arr
                If strKeyName.ToUpper = "CLSID" Then
                End If
                ky = ClassesRoot.OpenSubKey(strStart & "\" & strKeyName, False)
                If Not ky Is Nothing Then
                    arrValues = ky.GetValueNames()
                    For Each s As String In arrValues
                        'If s = "" Then s = "(Default)"
                        kyval = CurrentUser.OpenSubKey(strStart & "\" & strKeyName & "\" & s, False)
                        If Not kyval Is Nothing Then arrd = kyval.GetSubKeyNames()
                    i = arrValues.IndexOf(arrValues, strSearchFor)
                    If i > -1 Then
                        Return "Found It!"
                    End If

                    arrValues = ky.GetSubKeyNames()
                    For Each strSubKeyName As String In arrValues
                        If strSubKeyName.ToUpper = strSearchFor.ToUpper Then
                        End If
                        strResult = SearchKey(strStart & "\" & strKeyName & "\" & strSubKeyName, strSearchFor)
                        If strResult <> "" Then
                            Return "Found it!"
                        End If
                End If
        Catch ex As Exception
        End Try
    End Function

Finally, to call it:

SearchKey("AppEvents\EventLabels\AppGPFault", "sqldmo.dll")

As you can see, pass the start key and what to search for.

Let me know what you think.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ericvbAuthor Commented:
Hello RoverM,

Computer101 said : 'PAQed, with points refunded (200)', so I suppose that I setted it to 200 points? I don't know it anymore....

Thanks for your function, I will test it and let you know if it helps me.
(It will take me, maybe, some time, because I'v never worked with VB : must translate to C# or include this VB code in C# (I know it is possible, but did never do this before...))

Else add a VB module or class to your project.
Then you can copy/paste it into that and call it from C#.
Eric, any progress?
ericvbAuthor Commented:
Sorry Roverm,

I did not have the time yet to test your solution and I don't know if I shall have the time in the weeks to come.
The company who I work for is taken over by another company, so I must know spend my time to coordinate this takeover.

I know that you have administrator rights, so I propose that you take already 50% of the points on your count.
I thank you very match for your help, and I hope to test your solution soon.

Hi Eric,
No need to apologize.

I'm sorry to say that I don't longer have admin rights (I am no longer the PE of .NET) but even if I had then I wouldn't have done that.
Let's wait and see when you have time again.

Good luck with the take over.

ericvbAuthor Commented:
Hi Roverm,

I didn't have the time yet to test your solution, but as thank for answering my question, I will give you the points.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.