Re: Registy access via WMI in C#

From: Alek Davis (
Date: 01/14/03

From: "Alek Davis" <>
Date: Tue, 14 Jan 2003 09:29:31 -0800


I am just trying to understand why you are hooked on WMI. In general, WMI is
not recommended if you can accomplish the same operation using some other
methodology, because WMI is really slow. For example, getting a serial
number of a hard drive using WMI is 4000 (four thousand) times slower than
using native Win32 API via P/Invoke. So, unless you need WMI for something
you cannot accomplish otherwise, do not use it. If this is how you did it
before, it does not mean that you must continue doing it if there is a
better way.

I don't really know what WMI uses behind the scene. Most likely it is DCOM,
so you may be right. OpenRemoteBaseKey probably uses standard Win32 registry
API (e.g. RegOpenKey, or whatever it is) via P/Invoke (which many of .NET
classes do), and this API may or may not use DCOM. I just do not know. And
why would you care?

-- Alek

"Dr. Strangedub" <> wrote in message
> Thanks Alex -
> Well, after doing a bit of searching and tinkering yesterday, I did get
> OpenRemoteBaseKey to work for me. As mentioned before, our existing .asp
> use WMI (StdRegProv), so I figured we needed to code up analogous logic in
> Now, OpenRemoteBaseKey doesn't appear to use WMI, so I'm not exactly sure
how it
> works. (I know WMI uses DCOM under the covers - so perhaps this must also
> on DCOM?)
> -Michael Rose
> Unisys Corp
> On Mon, 13 Jan 2003 17:21:22 -0800, "Alek Davis"
> <> wrote:
> >
> >Why don't you simply use RegistryKey.OpenRemoteBaseKey method to open a
> >on remote machine? This sounds pretty straight-forward.
> >
> >-- Alek
> >
> >"Dr. Strangedub" <> wrote in message
> >
> >> We are in the process of converting some specialized ASP web
> >from
> >> asp (using VBScript / Javascript) to ASP.NET (using C#). One of the
> >functions
> >> of our applications is to update the Windows registry on a remote host
> >(either
> >> the host where the web exists, or another host). Today the server-side
> >VBScript
> >> uses WMI to access the registry via the StdRegProv class as follows:
> >> ==
> >> Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")
> >> Err.Clear ' Initialize error status
> >> lRC = objRegistry.CheckAccess(HKEY_LOCAL_MACHINE, shortPath,
> >lAccess,bGranted)
> >> ==
> >>
> >> I would appreciate any help (code samples, links, other docs) in coding
> >this
> >> logic in C#. We picked up the string "winmgmts:root\default:StdRegProv"
> >used on
> >> the GetObject call from an example at the online MSDN site -- and there
> >seemed
> >> to be no real explanation of how this string gets us to a Namespace.
> >>
> >> I know we could simply use the Microsoft.Win32 Namespace if our
> >access
> >> was limited to the localhost (i.e., the web server host), but we really
> >need
> >> to do remote updates as well.
> >>
> >> Thanks in advance for any help on this.
> >>
> >> -Michael G. Rose
> >> Unisys Corp.
> >>
> >>
> >>
> >
> >

Relevant Pages

  • Re: command prompt: tasklist logon failure
    ... The root of the problem was actually DCOM, which caused WMI to fail, ... caused WMI to run at the wrong permission level. ... tools that use DCOM for remote solution processes, ...
  • Re: XP Services Dependencies
    ... Check if there are "DCOM" entries in the Application Event logs. ... I'm wondering if this is inter-related with the other problem (Disk Management console) you're facing. ... Ramesh Srinivasan, Microsoft MVP ... WMIdiag>>> says I have some errors that may keep WMI from ...
  • Re: DCOM error, restarting
    ... This is an error in the WMI, ... marfers notes for windows xp ... > DCOM got error "The service database is locked. ...
  • Re: MSINFO32
    ... J Lunis wrote: ... Within 'Services,' WMI shows it is running. ... Start DCOM Server Process Launcher ... If you find that Office is acting strange you may want to enable those or reinstall Office. ...
  • Re: WMI32_PRODUCT not listed
    ... Making Win2003 inconsistent with other o/s in relation to this is bad. ... This is not to mention the numerous problems that users have configuring security on DCOM in order to get WMI to work (if it's not the Windows firewall it's some other antivirus product getting it's paws in the way - because they all know that DCOM is used for so many things that it presents a wide attack surface). ...