FREAKOUT
(Lurker)
2004-01-27 03:52 PM
WriteValue, REG_BINARY

Hi,

What am I doing wrong here ? I want to write hexadecimal to the reg key "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo" on subkeys "Company" and "UserName" the value "AAA".

It doesn't write it hexadecimal but in a unknown value (false characters) !

$rc=WriteValue
("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo","UserName",AAA,"REG_BINARY")
$rc=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo","Company",AAA,"REG_BINARY")

Thanks !


JochenAdministrator
(KiX Supporter)
2004-01-27 04:13 PM
Re: WriteValue, REG_BINARY

Hi there and welcome to the board,

you might try to enclose the value in quotes

[edit: sorry, forget my answer ]


LonkeroAdministrator
(KiX Master Guru)
2004-01-27 04:32 PM
Re: WriteValue, REG_BINARY

jochen, it's a good answer.
question 1, why do you write twice there?
question 2, how do you get AAA value there?
it does not let me do other than "AAA0"

you should read the correct value with kixtart and use that as the value what you write.


Richard H.Administrator
(KiX Supporter)
2004-01-27 04:33 PM
Re: WriteValue, REG_BINARY

Hmmm...

You have to write it in Unicode.

Give this a try:
Code:
$rc=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo","Company","4100410041000000","REG_BINARY")



FREAKOUT
(Lurker)
2004-01-28 09:14 AM
Re: WriteValue, REG_BINARY

That's the right solution !
Write the stringin Unicode ...
But how can I translate a ASCI string to Unicode ?
I would like "dynamically" translate the logged-in user to the $rc=WriteValue
("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo","UserName","THE_LOGGED-IN_USER","REG_BINARY")

Can yoy help me with this ?
Thanks


NTDOCAdministrator
(KiX Master)
2004-01-28 09:25 AM
Re: WriteValue, REG_BINARY

Please take a look here, there is already a posted UDF that works just fine for me.

http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Number=83554&page=35&view=collapsed&sb=3&o=all&fpart=2&vc=1



Richard H.Administrator
(KiX Supporter)
2004-01-28 09:36 AM
Re: WriteValue, REG_BINARY

Here is a little UDF to do the conversion for you.

The unicode "set" is hard-coded, but this should work in most cases.

Code:
Function udfStrToRegBin($s)
While $s
$udfStrToRegBin=$udfStrToRegBin+DecToHex(Asc(Left($s,1)))+"00"
$s=SubStr($s,2)
Loop
$udfStrToRegBin=$udfStrToRegBin+"0000"
EndFunction



To use it, just paste the function at the end of your script and call it like this:
Code:
$rc=WriteValue("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\UserInfo","UserName",udfStrToRegBin("THE_LOGGED-IN_USER"),"REG_BINARY")



FREAKOUT
(Lurker)
2004-01-28 11:04 AM
Re: WriteValue, REG_BINARY

It works ...
Thanks for the replies !