Adding entry to comm\tcpip\hosts

G

Guest

I am trying to figure out how to save aTCPIP address entry in the
comm\tcpip\hosts registy. I can make the host key with the name and save the
ipaddress key with a string value, but need to convert to binary value. I was
looking at the bitconverter, but didnt see what the conversion would be? Any
help would be great!

Dim nipaddress As string
Dim bipaddress As string
nipaddress = Hex(TextBox3.Text) + " " + Hex(TextBox4.Text) + " " +
Hex(TextBox5.Text) + " " + Hex(TextBox6.Text)

bipaddress=System.BitConverter.ToDouble(nipaddress)

Dim regVersion As OpenNETCF.Win32.RegistryKey
Dim keyName As String = "Comm\\Tcpip\\Hosts\\" + TextBox1.Text
regVersion = OpenNETCF.Win32.Registry.LocalMachine.CreateSubKey(keyName)
regVersion.SetValue("ipaddr", bipaddress)
regVersion.Close()
 
D

Daniel Moth

Not sure which value you think should be binary.. ipaddresses are stored as
strings in the registry... Assuming you got your paths right try it with a
string (you'll need to rebind your driver OR flush the registry and restart
the unit)

Note that you do not need to escape the backslashes in VB like your sample
shows...

Cheers
Daniel
 
G

Guest

Daniel,

Thanks, the string I am trying to save as binary is the bipaddress
I tested again as a string in the registry, doesnt work. I used a program
called "Pocket Hosts" to create a new hosts entry and it saves the ipadress
in a binary value key. I can convert the dec to binary, but I cant fingure
out how to save the key value as a binary key.
I can convert 192 168 2.3 to C0 A8 02 03 but the key type needs to be
binary. When I use the setvalue below is creates as a string, the response I
got from OpennetCf was "nipaddress needs to be a byte array for the data to
be written as a binary value" Is there a way to convert the string variable
to a binary variable?
 
D

Daniel Moth

Any registry code will write to the registry whatever you pass to it. To
write binary you must pass it a byte array. So if you have the bytes just
add them to a byte array and pass that to the SetValue method. If you have
more problems post your updated code indicating which line fails.

Cheers
Daniel
 
G

Guest

Encoding.ASCII.GetBytes

-Chris


WM said:
Daniel,

Thanks, the string I am trying to save as binary is the bipaddress
I tested again as a string in the registry, doesnt work. I used a program
called "Pocket Hosts" to create a new hosts entry and it saves the
ipadress
in a binary value key. I can convert the dec to binary, but I cant fingure
out how to save the key value as a binary key.
I can convert 192 168 2.3 to C0 A8 02 03 but the key type needs to be
binary. When I use the setvalue below is creates as a string, the response
I
got from OpennetCf was "nipaddress needs to be a byte array for the data
to
be written as a binary value" Is there a way to convert the string
variable
to a binary variable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top