Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine A Registry Value's Type
Message
From
11/07/2009 12:32:26
 
 
To
11/07/2009 12:22:55
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01410985
Message ID:
01411610
Views:
26
I'm just sipping a beer after helping at two mountain rescue callouts within an hour!
One suspected heart attack, one fractured ankle and only a couple of miles apart.
They ended up sending a SeaKing down from Kinloss in Scotland to airlift both of them out.
Luckily the weather was good.....

>I guess I could have played with it and figured it out easily enough (probably Kevin could have or already did) ... but I'm just sitting here sipping my coffee on a Saturday morning, so it was easier to ask you to clarify. <g>
>
>Thanks Viv (and Gregory too).
>
>~~Bonnie
>
>
>>Hmmm,
>>He actually asked how to determine the type so that the *could* cast it correctly - not how to cast it :-}
>>But anyway:
            switch (kind)
>>            {
>>                case RegistryValueKind.String:
>>                    {
>>                        string s = (string) o;
>>                        break;
>>                    }
>>                case RegistryValueKind.DWord:
>>                    {
>>                        int i = (int)o;
>>                        break;
>>                    }
>>                case RegistryValueKind.Binary:
>>                    {
>>                        byte[] b = (byte[])o;
>>                        break;
>>                    }
>>                    //Case etc....
>>            }
>>
>>>But Viv, I think that only answers part of Kevin's question. What do you do with it after that? IOW, you have this code:
>>>
>>>
>>>            RegistryValueKind kind = x.GetValueKind("Update Status");
>>>            Object o = x.GetValue("Update Status");
>>>
>>>
>>>Kevin doesn't want to use an Object o, he wanted to be able to cast the object returned from x.GetValue() to the proper type ... which, I'm assuming from your reply, has something to do with the RegistryValueKind kind. But the question is: what do you do with kind?
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>>I'm using Registry.GetValue(). GetValue returns an object. How do you know the type of data being returned,
>>>>>such as REG_SZ or REG_DWORD, so that it can be cast correctly?
>>>>
>>>>You need a RegistryKey instance for this. e.g.:
>>>>            RegistryKey rk = Registry.LocalMachine;
>>>>            RegistryKey x = rk.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
>>>>            RegistryValueKind kind = x.GetValueKind("Update Status");
>>>>            Object o = x.GetValue("Update Status");
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform