473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

using WMI in CSharp

Hi,

how can we get registry settings of a computer within local network using
WMI?

Lalit
Aug 24 '07 #1
4 6891
Lalit,

I don't know that you can get actual registry values through WMI. The
only class I see for this is the Win32_Registry class, which gives
information about the registry as a whole.

If you want to get actual values, you can call the static
OpenRemoteBaseKey method on the RegistryKey class in the Microsoft.Win32
namespace to get the RegistryKey on a remote machine.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lalit" <xy*@xyz.comwrote in message
news:e1**************@TK2MSFTNGP05.phx.gbl...
Hi,

how can we get registry settings of a computer within local network using
WMI?

Lalit


Aug 24 '07 #2
Thanks for the reply, I got a code from code project to read registry values
using WMI.

I stunk on one more problem now. I was able to get version number of com
dll but I want to get version of .Net dll and for .Net dlls it return NULL
in Version property.

Any Idea?
Lalit
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2***************@TK2MSFTNGP02.phx.gbl...
Lalit,

I don't know that you can get actual registry values through WMI. The
only class I see for this is the Win32_Registry class, which gives
information about the registry as a whole.

If you want to get actual values, you can call the static
OpenRemoteBaseKey method on the RegistryKey class in the Microsoft.Win32
namespace to get the RegistryKey on a remote machine.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lalit" <xy*@xyz.comwrote in message
news:e1**************@TK2MSFTNGP05.phx.gbl...
Hi,

how can we get registry settings of a computer within local network
using
WMI?

Lalit


Aug 24 '07 #3
"Lalit" <xy*@xyz.comwrote in message
news:ux**************@TK2MSFTNGP05.phx.gbl...
Thanks for the reply, I got a code from code project to read registry
values
using WMI.

I stunk on one more problem now. I was able to get version number of com
dll but I want to get version of .Net dll and for .Net dlls it return NULL
in Version property.

Any Idea?
Lalit
You need to use the StdRegProv class in WMI's root\default namespace.
Following snippet reads a DWORD value from HKCU to get you started. Consult
the WMI docs in MSDN for more details....

....
const uint HKEY_CURRENT_USER = 0x80000001;
ConnectionOptions co = new ConnectionOptions();
co.Username = "administrator"; // user with sufficient privs to read the
reg key
co.Password = "xxxxxxx"; // his pwd
string remMachine = "ssssss"; // remote machine name
ManagementPath p = new ManagementPath("StdRegProv");
ManagementScope scope = new ManagementScope(@"\\" + remMachine +
@"\root\default", co);
using (ManagementClass regClass = new ManagementClass(scope, p, null))
{
ManagementBaseObject inputArgs =
regClass.GetMethodParameters("GetDWORDValue");
inputArgs["hDefKey"] = HKEY_CURRENT_USER;
inputArgs["sSubKeyName"] = "Console";
inputArgs["sValueName"] = "HistoryBufferSize";
ManagementBaseObject outParams = regClass.InvokeMethod("GetDWORDValue",
inputArgs, null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret == 0)
Console.WriteLine("Success: {0}",
(uint)(outParams.Properties["uValue"].Value));
else Console.WriteLine("Failed with error code: {0}", ret);
}
....

Willy.

Aug 24 '07 #4
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uT**************@TK2MSFTNGP03.phx.gbl...
"Lalit" <xy*@xyz.comwrote in message
news:ux**************@TK2MSFTNGP05.phx.gbl...
>Thanks for the reply, I got a code from code project to read registry
values
using WMI.

I stunk on one more problem now. I was able to get version number of com
dll but I want to get version of .Net dll and for .Net dlls it return
NULL
in Version property.

Any Idea?
Lalit
And here is another sample that ilustrates how you can read an expanded
value from a remote systems registry. The sample reads the expanded %windir%
value from the system's environment, this value expands to the path where
the current running OS is stored.

static void GetExpandedWindir()
{
ConnectionOptions co = new ConnectionOptions();;
co.Username = "administrator";
co.Password = "xxxxx";
string remMachine = "ssssss";
ManagementPath p = new ManagementPath(@"StdRegProv");
ManagementScope scope = new ManagementScope(@"\\" + remMachine +
@"\root\default", co);
using (ManagementClass regClass = new ManagementClass(scope, p, null))
{
ManagementBaseObject inputArgs =
regClass.GetMethodParameters("GetExpandedStringVal ue");
inputArgs["sSubKeyName"] = @"SYSTEM\CurrentControlSet\Control\Session
Manager\Environment";
inputArgs["sValueName"] = "windir";
ManagementBaseObject outParams =
regClass.InvokeMethod("GetExpandedStringValue", inputArgs, null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret == 0)
Console.WriteLine("Success: {0}",
(string)(outParams.Properties["sValue"].Value));
else Console.WriteLine("Failed with error code: {0}", ret);
}
}

Willy.

Aug 24 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Doug | last post by:
I need to make the VB.NET object callable from a program called Trade Station. It is a stock analysis and trading tool that is very importiant to my company. They have a scripting languge called...
8
by: Dennis C. Drumm | last post by:
I have ordered the book .NET Framework Solutions, In Search of the Lost Win32 API by John Paul Meuller which I think will help answer some of my questions I have regarding making custom...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
5
by: a | last post by:
Is there a performance hit if I have many "using" statements that are unnecessary? For example: using System.Collections; when nowhere in my code I'm using System.Collections namespace. I'm...
1
by: rajani | last post by:
How to create control panel applet in CSharp. I know that a dll renamed as .cpl with cplapplet function exported has to be created which is not possible using csharp. Any help is appreciated. ...
1
by: Ricardo Lezana Bastante | last post by:
Hola a todos: ¿Como se puede acceder a Outlook Express desde un programa c#? Gracias Ricardo.
4
by: clintonG | last post by:
When using Visual Studio.NET I observe adding a new Web Form may have default References added such as... References o- System o- System.Data o- System.Drawing o- System.Web o- System.XML
2
by: news.microsoft.com | last post by:
Hi: I work in Csharp's parser files by LEX/YACC.Now I have only CSharp-lex.l and CSharp.y file,but they not have CSharp'comment Parse. this is a part of CSharp-lex.l. ........................
5
by: Deleo | last post by:
Hello, i still have my snmp in .net problem. But i thought i would write the snmp program in c++ and make a COM. Now i want to be able to use that COM in .net C# so i thought about using the COM+...
17
by: Sven Rutten | last post by:
Hello Actually I want to add some C#-Code to a VB.NET-Project in VS 2005. Normally I creating a DLL and importing that from the VB-Project. But as I am coding something for a Smart Device...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.