Creating Registry Keys

  • Thread starter Thread starter Cal
  • Start date Start date
C

Cal

The Help examples for creating a Registry subkey uses double backslashes
between subkeys.

The examples for creating a folder use a single backslash.

First: Am I right in that double backslashes are indeed needed with Registry
methods?

Second:Am I right in that single backslashes are indeed needed with folder
descriptions?

Third: Is there some reasonable explanation?


Thanks,
Cal
 
Hi Cal,

I reckon the chances are high that the Registry examples were in C#
where '\' has a special meaning and needs to be doubled to get a single '\'.

Single in both cases in VB and double in both cases with C#.

I assume that 'folder descriptions' means Folder paths. If not, what do
you mean?

Regards,
Fergus
 
* "Cal said:
The Help examples for creating a Registry subkey uses double backslashes
between subkeys.

The examples for creating a folder use a single backslash.

First: Am I right in that double backslashes are indeed needed with Registry
methods?

No, they are not needed when working with VB.NET.
Second:Am I right in that single backslashes are indeed needed with folder
descriptions?

What is a folder description?
Third: Is there some reasonable explanation?

The samples may be translated wrong from C#. In C# you have two ways to
"escape" the "\" character:

\\\
string s = @"Foo\Bla\Baz";
string t = "Foo\\Bla\\Baz";
///

If the latter is copied into VB.NET code directly, you get the two
backslashes. Here is a simple sample on reading a key's value by
locating it with a registry path:

\\\
Imports Microsoft.Win32
..
..
..
Dim pRegKey As RegistryKey = Registry.LocalMachine
pRegKey = pRegKey.OpenSubKey("HARDWARE\DESCRIPTION\System\CentralProcessor\0")
Dim val As Object = pRegKey.GetValue("VendorIdentifier")
MsgBox("The central processor of this machine is: " & val)
///
 
Thanks
Cal
Herfried K. Wagner said:
No, they are not needed when working with VB.NET.


What is a folder description?


The samples may be translated wrong from C#. In C# you have two ways to
"escape" the "\" character:

\\\
string s = @"Foo\Bla\Baz";
string t = "Foo\\Bla\\Baz";
///

If the latter is copied into VB.NET code directly, you get the two
backslashes. Here is a simple sample on reading a key's value by
locating it with a registry path:

\\\
Imports Microsoft.Win32
.
.
.
Dim pRegKey As RegistryKey = Registry.LocalMachine
pRegKey = pRegKey.OpenSubKey("HARDWARE\DESCRIPTION\System\CentralProcessor\0")
Dim val As Object = pRegKey.GetValue("VendorIdentifier")
MsgBox("The central processor of this machine is: " & val)
///
 
Back
Top