Simpel

Registry read out signed integer

4 posts in this topic

#1 ·  Posted (edited)

Hi,

I wondered why negative integers I wrote into registry (e.g. negative x-coordinates of a gui if using two monitors and the right one is the main one) wouldn't return right when reading. Now I know: it is saved as an unsigned integer (without algebraic sign). So here is a snippet that is changing unsigned to signed integer:

Global Const $g_sRegKey = "HKEY_CURRENT_USER\Software\" & @ScriptName ; path to registry

RegWrite($g_sRegKey, "Value", "REG_DWORD", -2147483647) ; write some negative integer into registry; -2147483647 highest possible negative integer , 2147483648 highest possible positive integer if talking of 32bit

Local $sValue = RegRead($g_sRegKey, "Value") ; read out registry
ConsoleWrite("Value: " & $sValue & @CRLF) ; show real value in console

Local $sResult = _SignedInteger($sValue) ; change to signed value
ConsoleWrite("Result: " & $sResult & @CRLF) ; and show it in console


Func _SignedInteger($iUnsignedInteger)
    Local $iSignedInteger
    If $iUnsignedInteger > (2^31) Then ; then it means a negative integer
        $iSignedInteger = $iUnsignedInteger - (2^32)
    Else
        $iSignedInteger = $iUnsignedInteger
    EndIf
    Return $iSignedInteger
EndFunc

It took me some time to find out the problem and so I hope I can help somebody with this.

Regards, Conrad

Edited by Simpel
tags

Share this post


Link to post
Share on other sites



#2 ·  Posted

13 hours ago, Simpel said:

-2147483647 highest possible negative integer , 2147483648 highest possible positive integer if talking of 32bit

Wrong values: it's [-2147483648, 2147483647] for an Int32.

Besides, under x64, it indeed seems that while the registry correctly records the binary value of the DWORD, retrieving it yields an Int64 under AutoIt.

Things behave correctly if the value is a REG_QWORD (Int64).


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#3 ·  Posted

@jchd I have to disagree. When I try my example and change the value I write to registry to -2147483648 it will return +2147483648. Writing 2147483648 returns +2147483648.

Thanks for the other info. So next time I try REG_QWORD.

Regards, Conrad

Share this post


Link to post
Share on other sites

#4 ·  Posted

I was just noting that the range of a 2's complement 32-bit integer is [-2147483648, 2147483647].

Since 2147483648 exceeds the signed 32-bit range, it's quite natural that it stores and retrieves a 64-bit value identical to the input. That's an indication that the registry datatype (e.g. DWORD vs QWORD) isn't as strict as one could imagine.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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

  • Similar Content

    • GreenSparks
      By GreenSparks
      Hi!
      I post here because i was wonderring if someone in this forum could help me with my script.
      What i'm trying to do, is to basically install a new keyboard layout in Windows and activate it. I want to acheive by the registry or the command line, but not with the autoit automation tools, i don't find it stable...
      Thanks for your help and have a good day!
    • Leo1906
      By Leo1906
      Hello guys,
      I'm having a problem right here ..
      I was trying to create a few Registry Values using autoit, but it seems to me that Autoit can't write those values to this specific part of the registry ..
      Here is the code I'm trying to run:
      RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\test\command", "", "REG_SZ", "C:\test\convert.exe %1 geojson|convert") I'm definitly sure that the path is correct. Script is runned with Admin Rights. Everything's fine here.
      It's possible to read other values stored by Windows in this directory:
      MsgBox(0, 0, RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.burn", "Description")) But you can't edit those using Autoit. I don't know what this is. In my eyes it's an Autoit Bug or something like that ...
      Possible solution for me is to write a ".reg" file and run it afterwards, but this is an unclean method I don't really want to use ..
      Any suggestions on this?
       
      Edit: the OS is Windows 7 x64 German Language btw ..
    • ur
      By ur
      I have a registry value in which the name is having \ and when I am trying to delete the registry,it is failing because of \.
      The registry is given below.
       
      Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Microsoft\Active Setup\Installed Components\{2D46B6DC-2207-486B-B523-A557E6D54B47}] "Version"="9,0,8112,16421" "Locale"="*" "C:\\ProgramData\\Symantec\\Symantec Endpoint Protection\\"="C:\\ProgramData\\Symantec\\Symantec Endpoint Protection\\" Can you please suggest how to delete the last value.
    • Wicked_Caty
      By Wicked_Caty
      I wanted to have a few lines that copy the whole registry into a file. I know that there is RegRead, but I don't want to type every single key into my code...
      Any way of doing this easily? Filetype doesn't matter, as long as it isn't encrypted. A batch or exe would be okay, if it's in the same location on every PC. Doing this without admin permissions would be awesome too
      Thanks
    • ViciousXUSMC
      By ViciousXUSMC
      Another project idea that I am trying to get working.
      A USB GPS device needs to be assigned COMM Port 25 when it is plugged into the computer.  It obviously gets the first open port when plugged in the first time and if I manually change it to 25 it will get a new port again if somebody plugs the device into a new USB port.
      So I want to make a script that can detect the device, and move/configure its port automatically.
      I started off finding this UDF: https://www.autoitscript.com/forum/topic/128546-serial-port-com-port-udf/?page=32
      It was useful for finding the device is plugged in and what port its on, but it does not have the ability to actually change the port.
      I think that will have to be done via registry, or perhaps via Objects.
      I just want to double check my facts here and get a grip on what I need to do.
      Registry has the following keys that change:
      HKLM\HARDWARE\SERIALCOMM - \Device\ProlificSerial0
      This key just lists the COMM Port for the device, it changes based on its current port.
      HKLM\SYSTEM\CurrentControlSet\Enum\USB\VID_067B&PID_2303]
      Under this key is a subkey that will duplicate every time the device gets a new port, I have not figure out quite yet how to determin what that subkey will be named, but it has the "FriendlyName" key and also the Device parameters\PortName key
      Both of those are unfortunately SYSTEM level permission so that makes scripting a change even harder.
      Last is HKLM\SYSTEM\CurrentControlSet\Control\COM Name Arbiter
      This contains the record of what comm ports are occupied or vacant via binary to hex.  I would have to find a way to read its current value and change it to show port 25 taken and if possible free up the port taken by the device before the change.  Not sure how to write something like that.
      Has anybody done something like this before?  If so what was your best approach?