I need to check if msdia100.dll is registered on a computer system that I'm running in order to register the dll with the command regsvr32.exe
. How can I do that with C#?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
The registry approaches are okay and worth doing, but to be sure you might also consider instantiating something from within the COM object wrapped in a try {} catch (COMException) {}, then present something sensible to the user if a COMException got caught.
You can search through the registry for this. Assuming that you don't know the COM objects contained in the DLL you'll have to start looking for the DLL name first in
HKEY_CLASSES_ROOT
.Then use the class name to find the CLSID in
HKEY_CLASSES_ROOT\[ClassName]\CLSID
and finally you should be able find it the CLSID asHKEY_CLASSES_ROOT\CLSID\[CLSID]
.Please note, registry locations written from memory so might be a bit off.
Edit: Or if you know the class name you could just try to create an instance of it and see if it works or not.
Verify if key exists using Microsoft.Win32.RegistryKey
Assuming you know the CLSID of the COM dll, you can just check if there's a key with that CLSID on
HKEY_CLASSES_ROOT\CLSID\{CLSID-of-your-COM-component}
orHKEY_CLASSES_ROOT\Wow6432Node\CLSID\{CLSID-of-your-COM-component}
(Wow6432Node => 32-bit COM registered on a 64-bit machine)e.g.
Look at the rgistry at HKEY_CLASSES_ROOT\CLSID\\InprocServer. If you have that record, then the DLL should be registered.
This is the proper way to do it. It does involve PInvoke but that' only because they haven't provided this capability in .NET directly.