tazyabi
asked on
'REG_MULTI__SZ' data type
How can I set a registry value as 'REG_MULTI__SZ' data type?
What programming language?... since null terminated strings are a bit easier to deal with in C/C++
ASKER
Vb.net
Pass and array of strings. each string must be null terminated. The last one double-null terminated.
Make sure you use regedt32 to see that the type is REG_MULTI_SZ
Dim oSubkey As Microsoft.Win32.RegistryKe y
oSubkey = Microsoft.Win32.Registry.C urrentUser .OpenSubKe y("Softwar e\Test", True)
Dim arrayWork(1) As String
arrayWork(0) = "teststring1" & Chr(0)
arrayWork(1) = "teststring2" & Chr(0) & Chr(0)
oSubkey.SetValue("TestValu e", arrayWork)
Make sure you use regedt32 to see that the type is REG_MULTI_SZ
Dim oSubkey As Microsoft.Win32.RegistryKe
oSubkey = Microsoft.Win32.Registry.C
Dim arrayWork(1) As String
arrayWork(0) = "teststring1" & Chr(0)
arrayWork(1) = "teststring2" & Chr(0) & Chr(0)
oSubkey.SetValue("TestValu
Oh yea. This code assumes the subkey test exists. So if it doesnt you will get an exception which you can trap with a try catch block and then use the createsubkey method of the RegistryKey class. I tested this on my system and it works.
Have fun.
Have fun.
me again...you will have to doubleclick on the "TestValue" in regedt32 to see all the data.
also just noticed it doesnt seem to care if the last string is double-nulled although in the past that has been the rule for REG_MULTI_SZ.
also just noticed it doesnt seem to care if the last string is double-nulled although in the past that has been the rule for REG_MULTI_SZ.
ASKER
I am trying to assign IP value of my LAN adapter.
It must be in REG_MULTI_SZ format and written in one single line.
I wrote the following code :
Dim IP_ADD (3) as string
IP_ADD(0)="10." & chr(0)
IP_ADD(1)="10." & chr(0)
IP_ADD(2)="10." & chr(0)
IP_ADD(3)="1" & chr(0)
regKey.SetValue("IPAddress ",IP_Add)
but when I check on IP address value on regedit I found the value assigned in multi line.
It must be in REG_MULTI_SZ format and written in one single line.
I wrote the following code :
Dim IP_ADD (3) as string
IP_ADD(0)="10." & chr(0)
IP_ADD(1)="10." & chr(0)
IP_ADD(2)="10." & chr(0)
IP_ADD(3)="1" & chr(0)
regKey.SetValue("IPAddress
but when I check on IP address value on regedit I found the value assigned in multi line.
Right...I see what you mean... I am looking at my registry.
I dont know how to get the single line. Maybe someone else can jump in on this.
I'll report back if I figure something out. Let me know if you figure it out as I am interested in the answer.
I dont know how to get the single line. Maybe someone else can jump in on this.
I'll report back if I figure something out. Let me know if you figure it out as I am interested in the answer.
okay I got it. Just kill the trailing zeros. Just pass an array of strings.
Apparently It an array of strings is passed vb.net knows it is a REG_MULTI_SZ. So vb.net and the Registry class take care all the trailing null stuff and we dont have to.
Try it out.
Apparently It an array of strings is passed vb.net knows it is a REG_MULTI_SZ. So vb.net and the Registry class take care all the trailing null stuff and we dont have to.
Try it out.
ASKER
did not work , it's still writing it in multi lines
Did you do it like this? With all the null characters removed. Cause it worked like a champ on mine. Removing the null characters totally eliminated the multiline problem.
I am using xp and vb net 2003.
You reworked your code like this?
Dim IP_ADD (3) as string
IP_ADD(0)="10."
IP_ADD(1)="10."
IP_ADD(2)="10."
IP_ADD(3)="1"
regKey.SetValue("IPAddress ",IP_Add)
I am using xp and vb net 2003.
You reworked your code like this?
Dim IP_ADD (3) as string
IP_ADD(0)="10."
IP_ADD(1)="10."
IP_ADD(2)="10."
IP_ADD(3)="1"
regKey.SetValue("IPAddress
ASKER
yes i have removed all chr(0).But it's still writing the value in multi lines.
me too using xp and vb net 2003
me too using xp and vb net 2003
don't know --- sorry.
Maybe try manually deleting the entry, if you havent already, and then recreating it with the no-null code.
Maybe try manually deleting the entry, if you havent already, and then recreating it with the no-null code.
also bear in mind that these ip addresses in the registry are for supporting more than one ip address per adapter.
So you code is incorrect in that you are trying to assign each octect to a array string.
Also I think you are making your array one two big.
So what the code below does for you.
I believe this is what you want
for assigning one ip address to an adapter
Dim IP_ADD (0) as string
IP_ADD(0)="10.10.10.1"
regKey.SetValue("IPAddress ",IP_Add)
for assigning two ip addresses to an adapter
Dim IP_ADD (1) as string
IP_ADD(0)="10.10.10.1"
IP_ADD(1)="10.10.10.2"
regKey.SetValue("IPAddress ",IP_Add)
See if that does the trick.
So you code is incorrect in that you are trying to assign each octect to a array string.
Also I think you are making your array one two big.
So what the code below does for you.
I believe this is what you want
for assigning one ip address to an adapter
Dim IP_ADD (0) as string
IP_ADD(0)="10.10.10.1"
regKey.SetValue("IPAddress
for assigning two ip addresses to an adapter
Dim IP_ADD (1) as string
IP_ADD(0)="10.10.10.1"
IP_ADD(1)="10.10.10.2"
regKey.SetValue("IPAddress
See if that does the trick.
also check out the IP Helper API. Here is the documentation at microsoft.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/ip_helper_function_reference.asp
the addipaddress function in particular:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/addipaddress.asp
ASKER
Ok, Could you give me a tested full vb net code for changing IP address of the network adapter? (And get more 500 points)
I don't have any ready made code.
I
Here is some c code that maybe could be ported:
http://codeguru.earthweb.com/internet/IPAD.html
I don't have any ready made code.
I
Here is some c code that maybe could be ported:
http://codeguru.earthweb.com/internet/IPAD.html
ASKER
Ok, do your best to give me this code in vb net
Please I am really in urgent need of this procedure.
(((1500 points for this code if you provide it in within 24 hours)))
Please I am really in urgent need of this procedure.
(((1500 points for this code if you provide it in within 24 hours)))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Marshawk's entirely right - simply saving it will work fine. The registry setting is a MULTI_SZ because you can have more than one IP address, of course, which you might want to bear in mind, before you overwrite the value. Therefore, you just have one string to save, not an array. If you've got XP, look at the binary data in regedit - you'll see it's just a normal null-terminated string.