reading the registry key

  • Thread starter Thread starter zoneal
  • Start date Start date
Z

zoneal

my program it's just tools for my little home network.. Only thing I
have left to do is reading the registy key
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\
"shared"]
to check the path to the shared folder.. this path is always updated so
I will always be able to find the folder if it's moved (i like this
idea!)

but I've had alot of trouble coding it even after tutorials
I just need it to show me the path to the shared folder by reading that
registly key.

I guess Im just asking you to show me how it's done, I truly give up on
this and reading tutorials

Thanks
 
my program it's just tools for my little home network.. Only thing I
have left to do is reading the registy key
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\
"shared"]
to check the path to the shared folder.. this path is always updated so
I will always be able to find the folder if it's moved (i like this
idea!)

but I've had alot of trouble coding it even after tutorials
I just need it to show me the path to the shared folder by reading that
registly key.

I guess Im just asking you to show me how it's done, I truly give up on
this and reading tutorials

Well, could you show us what you've tried? Ideally, post a short but
complete program which demonstrates the problem - just tries to print
out the value of the registry entry. Then say what *actually* happens
as well.

See http://www.pobox.com/~skeet/csharp/complete.html for more on this.

Jon
 
my program it's just tools for my little home network.. Only thing I
have left to do is reading the registy key
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\lanmanserver\
"shared"]
to check the path to the shared folder.. this path is always updated so
I will always be able to find the folder if it's moved (i like this
idea!)

but I've had alot of trouble coding it even after tutorials
I just need it to show me the path to the shared folder by reading that
registly key.

I guess Im just asking you to show me how it's done, I truly give up on
this and reading tutorials

Thanks

using System;
using Microsoft.Win32;
namespace MyNameSpace
{
public class Registry
{
public Registry()
{
}
public bool CreateKey(RegistryHive RootKey, string
SubKey)
{
bool blRetVal;
RegistryKey RKey =
RegistryKey.OpenRemoteBaseKey(RootKey,String.Empty);
blRetVal = false;
try
{
RegistryKey RSubKey =
RKey.CreateSubKey(SubKey);
blRetVal = true;
RSubKey.Close();
}
catch
{
blRetVal = false;
}
RKey.Close();
return blRetVal;
}
public object GetValue(RegistryHive RootKey, string
SubKey, string ValueName, object DefaultValue)
{
object oRetVal;
RegistryKey RKey =
RegistryKey.OpenRemoteBaseKey(RootKey,String.Empty);
oRetVal = null;
try
{
RegistryKey RSubKey =
RKey.OpenSubKey(SubKey);
oRetVal = RSubKey.GetValue(ValueName,
DefaultValue);
RSubKey.Close();
}
catch
{
oRetVal = DefaultValue;
}
RKey.Close();
return oRetVal;
}
public bool SetValue(RegistryHive RootKey, string
SubKey, string ValueName, object Value)
{
bool blRetVal;
RegistryKey RKey =
RegistryKey.OpenRemoteBaseKey(RootKey,String.Empty);
blRetVal = false;
try
{
RegistryKey RSubKey =
RKey.OpenSubKey(SubKey,true);
RSubKey.SetValue(ValueName, Value);
RSubKey.Close();
blRetVal = true;
}
catch
{
blRetVal = false;
}
RKey.Close();
return blRetVal;
}
}
}


Leon
 

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

Back
Top