Registrykey reading problems

Hi,

I'm trying to read a registry key:

I've tried:

RegistryKey rkey1 = rkey.OpenSubKey(
"SYSTEM\\CurrentControlSet\\Services\\Rendering Service");

then
RegistryKey rkey1 = rkey.OpenSubKey(
"SYSTEM\\CurrentControlSet\\Services\\Rendering Service\\");
due to problems

I've tried

RenderingQ = rkey1.GetValue("RenderingQOnDemandQ");

which gave an error when compiling of
Error 6 Cannot implicitly convert type 'object' to 'string'. An
explicit conversion exists (are you missing a cast?)

which seems weird, from the documentation I thought GetValue returned
a string?
so I tried:

RenderingQ = rkey1.GetValue("RenderingQOnDemandQ").ToString();

that compiles.

When I run it however I get a null value exception (the same situation
exists for all the various keys I'm working with)

if I do a registry dump of the key I'm working with I get:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Render ing
Service]

and
"RenderingQOnDemandQ"="C:\\RenditionServerQ\\QueueManagerQ\\ OnDemandQ"

So I suppose there is something simple that i don't know about working
with the registry in .Net that someone can help me with?

Is it a casting exception?
How should I cast?
bryan rasmussen [ Mo, 31 März 2008 10:42 ] [ ID #1932463 ]

Re: Registrykey reading problems

On Mar 31, 10:42 am, pantagruel <rasmussen.br... [at] gmail.com> wrote:
> Hi,
>
> I'm trying to read a registry key:
>
> I've tried:
>
> RegistryKey rkey1 = rkey.OpenSubKey(
> "SYSTEM\\CurrentControlSet\\Services\\Rendering Service");
>
> then
> RegistryKey rkey1 = rkey.OpenSubKey(
> "SYSTEM\\CurrentControlSet\\Services\\Rendering Service\\");
> due to problems
>
> I've tried
>
> RenderingQ = rkey1.GetValue("RenderingQOnDemandQ");
>
> which gave an error when compiling of
> Error 6 Cannot implicitly convert type 'object' to 'string'. An
> explicit conversion exists (are you missing a cast?)
>
> which seems weird, from the documentation I thought GetValue returned
> a string?
> so I tried:
>
> RenderingQ = rkey1.GetValue("RenderingQOnDemandQ").ToString();
>
> that compiles.
>
> When I run it however I get a null value exception (the same situation
> exists for all the various keys I'm working with)
>
> if I do a registry dump of the key I'm working with I get:
>
> [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Render ing
> Service]
>
> and
> "RenderingQOnDemandQ"="C:\\RenditionServerQ\\QueueManagerQ\\ OnDemandQ"
>
> So I suppose there is something simple that i don't know about working
> with the registry in .Net that someone can help me with?
>
> Is it a casting exception?
> How should I cast?

oops, obviously should note that rkey is RegistryKey rkey =
Registry.LocalMachine;
bryan rasmussen [ Mo, 31 März 2008 10:52 ] [ ID #1932464 ]

Re: Registrykey reading problems

It definitely returns an object - after all, not all attributes are strings.

You might want to double-check the key name; equally, using string literals
(i.e. [at] "foo") can make it easier to avoid escaping issues. Using a different
key (that exists on my machine) the following works fine:

string value = Convert.ToString(
Registry.GetValue( [at] "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControl Set\Services\RemoteAccess",
[at] "DisplayName", null));

Marc
Marc Gravell [ Mo, 31 März 2008 10:54 ] [ ID #1932466 ]

RE: Registrykey reading problems

Be aware that registry virtualization on Vista or 64bit OS's will mess up
your mind in this scenario. If you are on 32 bit XP however, I don't see why
this wouldn't work, given the key is specified correctly.

"pantagruel" wrote:

> Hi,
>
> I'm trying to read a registry key:
>
> I've tried:
>
> RegistryKey rkey1 = rkey.OpenSubKey(
> "SYSTEM\\CurrentControlSet\\Services\\Rendering Service");
>
> then
> RegistryKey rkey1 = rkey.OpenSubKey(
> "SYSTEM\\CurrentControlSet\\Services\\Rendering Service\\");
> due to problems
>
> I've tried
>
> RenderingQ = rkey1.GetValue("RenderingQOnDemandQ");
>
> which gave an error when compiling of
> Error 6 Cannot implicitly convert type 'object' to 'string'. An
> explicit conversion exists (are you missing a cast?)
>
> which seems weird, from the documentation I thought GetValue returned
> a string?
> so I tried:
>
> RenderingQ = rkey1.GetValue("RenderingQOnDemandQ").ToString();
>
> that compiles.
>
> When I run it however I get a null value exception (the same situation
> exists for all the various keys I'm working with)
>
> if I do a registry dump of the key I'm working with I get:
>
> [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Render ing
> Service]
>
> and
> "RenderingQOnDemandQ"="C:\\RenditionServerQ\\QueueManagerQ\\ OnDemandQ"
>
> So I suppose there is something simple that i don't know about working
> with the registry in .Net that someone can help me with?
>
> Is it a casting exception?
> How should I cast?
>
>
>
>
>
FamilyTreeMike [ Mo, 31 März 2008 13:21 ] [ ID #1932471 ]
Microsoft » microsoft.public.dotnet.general » Registrykey reading problems

Vorheriges Thema: Hierarchial Update
Nächstes Thema: Checking for DBNull with generics