VB.NET variant arrays

G

Guest

Hell

I'm wondering if anyone can shed some light on this? I'm trying to
enumerate the uninstall registry key (to display installed applications)
with VB.NET and WMI
I'm pretty stuck. When I try to collect the installed software via a
call to EnumKey, I get a type mismatch (the exact erro
is: "System.Runtime.InteropServices.COMException (0x80041005): Typ
mismatch"

The code that causes the problem is below

The problem basically boils down to the fact that the EnumKey method o
StdRegProv wants the sNames as a variant array. I'm passing it a
Object array, because VB.Net doesn't have variant types like VB6. For
the lif
of me I cannot find any information on the Microsoft site, newsgroups,
or anywhere else on the internet. Any help would be great

Here's the code

Private Sub testsub(
Dim HKEY_LOCAL_MACHINE As Long = &H8000000
Dim sNames() As Objec
Dim sPath As Strin
Dim objLocator, objWMI, objRegistry As Objec

objLocator = CreateObject("WbemScripting.SWbemLocator"
objWMI = objLocator.ConnectServer(target, "root\default"
objWMI.Security_.ImpersonationLevel = 3 'Impersonat
objRegistry = objWMI.Get("StdRegProv"

sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

objRegistry.EnumKey(HKEY_LOCAL_MACHINE, sPath, sNames) ' <--
Dies on this lin
End Su

And just so it's clear, it boils down to this situation: I nee
someMethod to populate someVariantArray for me inside it. Here's a
example

someObject.someMethod(someVariantArray

Thank
RF
 
M

Mattias Sjögren

I'm pretty stuck. When I try to collect the installed software via a
call to EnumKey, I get a type mismatch (the exact error
is: "System.Runtime.InteropServices.COMException (0x80041005): Type
mismatch")

Probably because HKEY_LOCAL_MACHINE is declared as Long, which is 64
bits in VB.NET unlike VB6 where it was 32 bits.

That said, I'd recommend you to use the Microsoft.Win32.Registry
classes for registry access instead.



Mattias
 
G

Guest

Mattias,

Thank you! Your advise was 100% dead on! The problem has been fixed!


----- Mattias Sjögren wrote: -----
Probably because HKEY_LOCAL_MACHINE is declared as Long, which is 64
bits in VB.NET unlike VB6 where it was 32 bits.
classes for registry access instead.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top