Jump to content

Read and List Bitor Value


Adele
 Share

Recommended Posts

Hello, i want to hide drives on Windows Explorer by using a registry trick https://www.tenforums.com/tutorials/79149-hide-specific-drives-windows.html. The values for each drive
A:\ 1 (Index 0)
B:\ 2 (Index 1)
C:\ 4 (Index 2)
D:\ 8 (Index 3)
.......................
multiples by index. If i want to hide B:\ and D:\ drives I use BitOR(2,8)=10 or 2+8=10 and write this value to registry.
I've prepared this code to show the logic.

$value = 0

For $i=1 To $count
    If $aCheckedDrives[$i]=True Then $value+= 2^$i
EndIf

RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer", "NoDrives", "REG_DWORD", $value)

The problem is, i want to read the value written before in registry and list all the drives hidden. I know reg functions and other things but the point i stucked is math and bit operations to list them. I can square root but the value is sum we don't know how much value there are. It may 16+128 or 256+1024+8192 etc. For example, i got 96 value from registry, how can i get indexes of drives again? I can do rest of it.  Thank you!

Edited by Adele
Link to comment
Share on other sites

Here's a very simple example:

#AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 -w 6 -d

#include <Constants.au3>

example()
Func example()

    Local $iDrives = 10 ;   1010 (binary)
    ;                       DCBA
    ;                       │  │
    ;                       │  └>2^0
    ;                       └>2^3

    If BitAND($iDrives, 2^0) Then ConsoleWrite("Drive A:" & @CRLF) ;1 in decimal
    If BitAND($iDrives, 2^1) Then ConsoleWrite("Drive B:" & @CRLF) ;2 in decimal
    If BitAND($iDrives, 2^2) Then ConsoleWrite("Drive C:" & @CRLF) ;4 in decimal
    If BitAND($iDrives, 2^3) Then ConsoleWrite("Drive D:" & @CRLF) ;8 in decimal

EndFunc

Output:

Drive B:
Drive D:

Or

#include <Constants.au3>
#include <Array.au3>

Const $DRIVE_ARRAY = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "", $STR_NOCOUNT)

;                                                           ZY XWVU TSRQ PONM LKJI HGFE DCBA
_ArrayDisplay(get_drives(10),  "Drives = 10")              ;00 0000 0000 0000 0000 0000 1010 (BD)
_ArrayDisplay(get_drives(96),  "Drives = 96")              ;00 0000 0000 0000 0000 0110 0000 (FG)
_ArrayDisplay(get_drives(252), "Drives = 252")             ;00 0000 0000 0000 0000 1111 1100 (CDEFGH)
_ArrayDisplay(get_drives(33554432),  "Drives = 33554432")  ;10 0000 0000 0000 0000 0000 0000 (Z)

Func get_drives($iDrives)
    #cs
        Binary bits
        ZYXWVUTSRQPONMLKJIHGFEDCBA
        │                        │
        └>2^25                   └>2^0
    #ce

    Local $aDrives[0]

    ;Identify each bit that is set (0 - 25)
    For $i = 0 To 25
        If BitAND($iDrives, 2 ^ $i) Then _ArrayAdd($aDrives, $DRIVE_ARRAY[$i])
    Next

    Return $aDrives
EndFunc

 

Edited by TheXman
Corrected binary representation decimal 10 =1010b
Link to comment
Share on other sites

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...