Jump to content
Sign in to follow this  
Tigerweld

read and write to registry

Recommended Posts

Trying to read a DWord value, but cannot seem to get it right. Can someone tell me what I'm doing wrong? I want to test a value. If the value is 1, then change it to a 2. Should I use Dword, string, or binary value?

$var = RegRead("HKLM\SOFTWARE\ALTIRIS\FLAGCHECK" , "FLAG")

if $var = "1" Then

MsgBox(4096, "Value" , "Value is:" & $var)

EndIf

Share this post


Link to post
Share on other sites

Trying to read a DWord value, but cannot seem to get it right. Can someone tell me what I'm doing wrong? I want to test a value. If the value is 1, then change it to a 2. Should I use Dword, string, or binary value?

$var = RegRead("HKLM\SOFTWARE\ALTIRIS\FLAGCHECK" , "FLAG")

if $var = "1" Then

MsgBox(4096, "Value" , "Value is:" & $var)

EndIf

Well what's wrong with it?

$var = RegRead("HKLM\SOFTWARE\ALTIRIS\FLAGCHECK" , "FLAG")

If @error Then

MsgBox(0, "Test - Error", @error)

Else

MsgBox(0, "Test", $var)

EndIf

What's the result of that?


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites

Well what's wrong with it?

$var = RegRead("HKLM\SOFTWARE\ALTIRIS\FLAGCHECK" , "FLAG")

If @error Then

MsgBox(0, "Test - Error", @error)

Else

MsgBox(0, "Test", $var)

EndIf

What's the result of that?

No matter the value, I get the msgbox. What type of reg value should I use to test for numbers?

Share this post


Link to post
Share on other sites

You don't specify the type on a RegRead() only on RegWrite, and the returned value will depend on the type read. You get an integer back for REG_DWORD, and a string back for everything else. For example:

$sRegKey = "HKCU\SOFTWARE\AutoIt v3\Temp"

_RegTypeTest("REG_BINARY", Binary("0xFEDCBA9876543210"))
_RegTypeTest("REG_SZ", "This is my string.")
_RegTypeTest("REG_MULTI_SZ", "String line one." & @LF & "String line two." & @LF & "String line three.")
_RegTypeTest("REG_EXPAND_SZ", "%TEMP%\AutoIt3")
_RegTypeTest("REG_DWORD", 1234567890)

Func _RegTypeTest($sType, $varData)
    RegWrite($sRegKey, "Test_" & $sType, $sType, $varData)
    ConsoleWrite("Debug: Wrote Test_" & $sType & " = " & $sType & " = " & $varData & @LF)
    $RegData = RegRead($sRegKey, "Test_" & $sType)
    $iType = @extended
    ConsoleWrite("Debug: Read Test_" & $sType & " = " & $iType & " = " & VarGetType($RegData) & " = " & $RegData & @LF & @LF)
EndFunc   ;==>_RegTypeTest

Note I passed a binary in to a REG_BINARY but got a string back.

And the REG_EXPAND_SZ did not expand the environment variable. You can cause it to expand with Opt("ExpandEnvStrings", 1), but that is global and not specific to this REG data type. So REG_EXPAND_SZ seems to mean nothing but REG_SZ, at least as implemented in AutoIt.

:)


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

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  

×
×
  • Create New...