Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determine A Registry Value's Type
Message
De
11/07/2009 13:35:28
 
 
À
11/07/2009 12:51:28
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01410985
Message ID:
01411619
Vues:
27
>>I'm just sipping a beer after helping at two mountain rescue callouts within an hour!
>
>And a well-deserved beer too, I suspect! What was your involvement in the mountain rescue? Are you a volunteer or do you do this sort of thing on a regular basis?
>
>~~Bonnie

Nothing official. We've got a quad bike on the farm and a lot of the mountain is accessible if you know the ways so I'm often asked to help out.
Lucky it happened earlier - the cloud base is down to about 1200' now....

>
>
>>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");
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform