Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determine A Registry Value's Type
Message
De
11/07/2009 12:15:28
 
 
À
11/07/2009 11:59:52
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01410985
Message ID:
01411607
Vues:
32
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform