Sign in to follow this  
Followers 0
gseller

RegWrite using a variable?

5 posts in this topic

#1 ·  Posted (edited)

Hi all,

I am reading a registry key and writing to an ini, this is to make a change back after another process. I am writing a REG_BINARY using a string from this ini as in the help file. I cannot get this variable $rIni[$i][1] to be written to the reg. it errors out. If I make this a simple string line kk05 it will write it. Can someone offer a king work to help me please?

Thank You in advance...

edit:forgot a word

$sIni = @ScriptDir & "\xxxxxxx.ini"
$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\XXXXXXX", "Workstation ID")
;MsgBox(4096, "Workstation ID:", $var)

; Demonstrate creating a new section using a string as input.
;$sData = $var
;IniWriteSection($sIni, "Section1", $sData)

IniWrite(@ScriptDir & "\xxxxxxx.ini", "section", "key", $var)

 

$rIni = IniReadSection(@ScriptDir & "\xxxxxxx.ini", "section")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $rIni[0][0]
        MsgBox(4096, "", $rIni[$i][1])
    Next
EndIf

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\XXXXXXX", "Workstation ID", "REG_BINARY", $rIni[$i][1])
Edited by gesller

Share this post


Link to post
Share on other sites



Thanks, not sure how that would work, but thank you for the reply :P

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi all,

I am reading a registry key and writing to an ini, this is to make a change back after another process. I am writing a REG_BINARY using a string from this ini as in the help file. I cannot get this variable $rIni[$i][1] to be written to the reg. it errors out. If I make this a simple string line kk05 it will write it. Can someone offer a king work to help me please?

Thank You in advance...

edit:forgot a word

$sIni = @ScriptDir & "\xxxxxxx.ini"
$var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\XXXXXXX", "Workstation ID")
;MsgBox(4096, "Workstation ID:", $var)

; Demonstrate creating a new section using a string as input.
;$sData = $var
;IniWriteSection($sIni, "Section1", $sData)

IniWrite(@ScriptDir & "\xxxxxxx.ini", "section", "key", $var)

$rIni = IniReadSection(@ScriptDir & "\xxxxxxx.ini", "section")
If @error Then 
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $rIni[0][0]
        MsgBox(4096, "", $rIni[$i][1])
    Next
EndIf

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\XXXXXXX", "Workstation ID", "REG_BINARY", $rIni[$i][1])

Your RegWrite is outside the For/Next loop, so only the last value gets written, but maybe that's intended...

Quoting the help file under RegRead():

When reading a REG_BINARY key the result is a binary datatype (in previous versions it was a string of hex characters).

When you RegRead() a REG_BINARY type the variable is a binary, which cannot be directly stored in an .ini file. The IniWrite() function probably converts it to a hex char string for you, but IniRead() will certainly give you a string, which you may need to convert back to binary before RegWrite():
$bIni = Binary($rIni[$i][1])
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Telephony\XXXXXXX", "Workstation ID", "REG_BINARY", $bIni)

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

PsaltyDS, I thought that too.. Thought I was gonna have to do a string split and put in a coma delimiter but thank God, it worked.. I was able to get the variable to regwrite by putting the regwrite back in the for loop. It all works now if it is split up from regread and write to an ini in one function and the regwrite in another. Thanks so much for your help...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0