Jump to content
Sign in to follow this  
brian75

Help with BitOR

Recommended Posts

brian75

Greetings All,

I'm trying to write a script that will interrogate the COM Name Arbiter in the registry on a Windows 7 64 bit box to see what COM ports are currently reserved and add some reservations to it.  The ComDB value is in hex so I think I can use BitOR to compare what the reservations are to what I want them to be but I'm a little fuzzy on the use of BitOR so I might be wrong.  Here's my code....such as it is:

Local $COMDBRead = RegRead ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter", "ComDB")
Local $COMDBreserve = "0xC003"
Local $COMDBcompare = BitOR ($COMDBreserve, $COMDBRead)
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter", "ComDB", "REG_BINARY", $COMDBcompare)

Once I do the RegRead, $COMDBRead ends up being something like 0x350000 (followed by a bunch more zeros). $COMDBreserve represents the additional COM ports I want to reserve.  After doing the BitOR the new value written back to ComDB isn't right.  I think I'm doing something wrong with BitOR...can anyone point me in the right direction?  Thanks much for any help!

Share this post


Link to post
Share on other sites
BrewManNH

BitOr works with 32 bit number, does the value retrieved from that registry key fit into 32 bits? It might be a 64 bit number, which is why it's getting changed when you use BitOr. Try it with just addition instead of BitOr and see if that changes anything, especially seeing as how the last numbers are all zeros anyways.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
brian75

Thanks BrewManNH, a buddy who was helping me on this figured out a solution which seems to work:

Global $COMDBReserve = "0xC003000000000000000000000000000000000000000000000000000000000000"
Global $PaddedZeros = "000000000000000000000000000000000000000000000000000000000000"
$COMDBReserve = BinaryMid($COMDBReserve, 1, 4)
Local $COMDBRead = RegRead ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter", "ComDB")
$COMDBRead = BinaryMid($COMDBRead, 1, 4)
Local $COMDBcompare = BitOR (Int($COMDBRead), Int($COMDBReserve))
$COMDBCompare = Binary($COMDBCompare) & $PaddedZeros
RegWrite ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\COM Name Arbiter", "ComDB", "REG_BINARY", $COMDBcompare)

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  

×