Click here to Skip to main content
15,843,327 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I was trying to read a simple registry keyvalue using the below code:
VB
Dim aa As Object
aa = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Avira\\AntiVir Desktop", "LastCommandLine", Nothing)


aa variable value is always Nothing.

What am I doing wrong here?
Please advise.

Then I tried the same in C# code and its working fine.
The code is As below:
object  aa = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Avira\\AntiVir Desktop","LastCommandLine",null);
Posted
Updated 9-Oct-12 10:34am
v2

1 solution

Try
VB
Dim aa As Object
       aa = Registry.GetValue("HKEY_CURRENT_USER\Software\Avira\AntiVir Desktop", "LastCommandLine", Nothing)


Can you see why? The key value you really need is "HKEY_CURRENT_USER\Software\Avira\AntiVir Desktop"; and the double '\\' simply means escaped '\', by C# syntax, not VB.NET. To make C# code similar, use verbose modifier '@':
C#
object aa = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Avira\AntiVir Desktop","LastCommandLine", null);


Better now? :-)

—SA
 
Share this answer
 
v5
Comments
arun_pk 9-Oct-12 13:35pm    
not better .. just the best :) my 5
Sergey Alexandrovich Kryukov 9-Oct-12 13:38pm    
You accepted it -- thank you, but probably forgot to vote :-)
--SA
RaisKazi 9-Oct-12 13:45pm    
Here you Go!
Sergey Alexandrovich Kryukov 9-Oct-12 13:50pm    
You, too? :-)
Thank you, Rais.
--SA
arun_pk 9-Oct-12 13:56pm    
done thank you Sergey

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900