No 3rd party solution needed:
Access Registry Using C#
By Gokula Giridaran

Access the registry using C#. Find out the system Information. Using
this source code.

/* I used it find Processor Information and Bios Information*/

using System;
using Microsoft.Win32;

class reg {
  static void Main() {
  RegistryKey hklm =Registry.LocalMachine;

hklm=hklm.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0
");
  Object obp=hklm.GetValue("Identifier");
  Console.WriteLine("Processor Identifier :{0}",obp);

  RegistryKey hklp =Registry.LocalMachine;

hklp=hklp.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0
");
  Object obc=hklp.GetValue("VendorIdentifier");
  Console.WriteLine("Vendor Identifier    :{0}",obc);

  RegistryKey biosv =Registry.LocalMachine;

biosv=biosv.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\MultiFunctionAdap
ter\\4");
  Object obv=biosv.GetValue("Identifier");
  Console.WriteLine("Bios Status          :{0}",obv);

  RegistryKey biosd =Registry.LocalMachine;
  biosd=biosd.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
  Object obd=biosd.GetValue("SystemBiosDate");
  Console.WriteLine("Bios Date            :{0}",obd);

  RegistryKey bios =Registry.LocalMachine;
  bios=bios.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\");
  Object obs=bios.GetValue("Identifier");
  Console.WriteLine("System Identifer     :{0}",obs);
 }
}

>From http://www.csharphelp.com/archives/archive48.html


-----Original Message-----
From: dotnet discussion [mailto:[EMAIL PROTECTED]] On Behalf Of
Bill Schmidt
Sent: Saturday, May 18, 2002 9:54 PM
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] Win32 API syntax problem, using C#

Duncan,

I assume you're referring to a 3rd-party solution -- one which I'd like
to
hear some more about.  That sounds like a potentially good solution in a
real-world, work environment.

Unfortunately, I'm one of the huge ranks of unemployed senior
developers,
so I'm converting this app only as a learning exercise.  Learning how to
do
Win32 API calls from C# is probably more useful in my situation.

As long as we're on that subject, don't hesitate to e-mail if anyone is
even thinking of hiring a senior VB/ASP/COM+/.NET developer in the
Philadelphia - Wilmington, DE region.  I'm your man!

Bill

On Sun, 19 May 2002 01:56:17 +0100, Duncan Godwin
<[EMAIL PROTECTED]> wrote:

>Wouldn't it be better if you are porting the app to C# to make use of
the
>Frameworks Registry functions which are far more maintainable and
easier to
>get working.
>
>----- Original Message -----
>From: "Bill Schmidt" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Saturday, May 18, 2002 6:19 PM
>Subject: [DOTNET] Win32 API syntax problem, using C#
>
>
>> I'm trying to convert a working VB.NET WinForms application to C#,
and
I'm
>> having trouble with the string buffer being returned from a Win32 API
>call.
>>
>> First, my working VB.NET code:
>>     Public Declare Function GetPrivateProfileString Lib "kernel32" _
>>         Alias "GetPrivateProfileStringA" _
>>         (ByVal lpApplicationName As String, _
>>         ByVal lpKeyName As String, ByVal lpDefault As String, _
>>         ByVal lpReturnedString As String, ByVal nSize As Integer, _
>>         ByVal lpFileName As String) As Integer
>>
>>     lngSize = 127
>>     strDBLocation = Space(lngSize) & Chr(0)
>>     lngDummy = GetPrivateProfileString("DBLocation", "Path", _
>>             vbNullString, strDBLocation, lngSize, strINIPath)
>>     strDBLocation = Left(strDBLocation, InStr(strDBLocation, Chr(0))
- 1)
>>
>> This code returns the correct strDBLocation string.  It also sets
lngDummy
>> to the length of the returned string (23).
>>
>> Now, what I think is the equivalent C# code:
>>     [DllImport("kernel32.dll", EntryPoint="GetPrivateProfileStringA",
>>  CharSet=CharSet.Ansi)]
>>  public static extern int GetPrivateProfileString(
>>  string lpApplicationName, string lpKeyName, string lpDefault,
>>  string lpReturnedString, int nSize, string lpFileName);
>>
>>     intSize = 127;
>>     strDBLocation = new string(' ', intSize) + (char) 0;
>>     intDummy = GetPrivateProfileString("DBLocation", "Path", null,
>>  strDBLocation, intSize, strINIPath);
>>     i = strDBLocation.IndexOf((char) 0);
>>     if (i >= 0)
>>  strDBLocation = strDBLocation.Substring(0, i);
>>
>> When I run this in the identical environment, intDummy gets set to 23
>> (which is correct), but strDBLocation remains the same as before the
call
>> to GetPrivateProfileString (a 127-char string filled with spaces).  I
>> verified that strINIPath is set to the same value as in the VB app.
>>
>> Can someone please tell me what I'm doing wrong?  (I've tried
switching
to
>> CharSet.Auto and CharSet.Unicode, with no success.)
>>
>> Bill
>>
>> You can read messages from the DOTNET archive, unsubscribe from
DOTNET,
or
>> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
>You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
>subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.351 / Virus Database: 197 - Release Date: 4/19/2002

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to