Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determine A Registry Value's Type
Message
De
11/07/2009 12:22:55
 
 
À
11/07/2009 12:15:28
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01410985
Message ID:
01411609
Vues:
26
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");
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform