Subz

How to return configured flags from an attribute?

5 posts in this topic

Would someone be able to point me in the right direction as to how I would find out which flags have been configured based upon a combined value?

For example: If I find a print driver with the attribute "0x00000041" I would like to return the string: "PRINTER_DRIVER_PACKAGE_AWARE; PRINTER_DRIVER_CATEGORY_FAX" from the array below.  While I could use a switch/case for each iteration i.e. 0x..1, 0x..2, 0x..3 etc.. I was wondering if someone knew of a simple function that could help, I thought Bitwise operations could help, but can't make heads or tails of how these work.
 

Local $aPrintDriverAttribs[11][2]
$aPrintDriverAttribs[0][0] = 0x00000001
$aPrintDriverAttribs[0][1] = "PRINTER_DRIVER_PACKAGE_AWARE; "
$aPrintDriverAttribs[1][0] = 00000002
$aPrintDriverAttribs[1][1] = "PRINTER_DRIVER_XPS; "
$aPrintDriverAttribs[2][0] = 0x00000004
$aPrintDriverAttribs[2][1] = "PRINTER_DRIVER_SANDBOX_ENABLED; "
$aPrintDriverAttribs[3][0] = 0x00000008
$aPrintDriverAttribs[3][1] = "PRINTER_DRIVER_CLASS; "
$aPrintDriverAttribs[4][0] = 0x00000010
$aPrintDriverAttribs[4][1] = "PRINTER_DRIVER_DERIVED; "
$aPrintDriverAttribs[5][0] = 0x00000020
$aPrintDriverAttribs[5][1] = "PRINTER_DRIVER_NOT_SHAREABLE; "
$aPrintDriverAttribs[6][0] = 0x00000040
$aPrintDriverAttribs[6][1] = "PRINTER_DRIVER_CATEGORY_FAX; "
$aPrintDriverAttribs[7][0] = 0x00000080
$aPrintDriverAttribs[7][1] = "PRINTER_DRIVER_CATEGORY_FILE; "
$aPrintDriverAttribs[8][0] = 0x00000100
$aPrintDriverAttribs[8][1] = "PRINTER_DRIVER_CATEGORY_VIRTUAL; "
$aPrintDriverAttribs[9][0] = 0x00000200
$aPrintDriverAttribs[9][1] = "PRINTER_DRIVER_CATEGORY_SERVICE; "
$aPrintDriverAttribs[10][0] = 0x00000400
$aPrintDriverAttribs[10][1] = "PRINTER_DRIVER_SOFT_RESET_REQUIRED; "

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I am sure there is a better way to do it ... but how about this?

func _getBinaryWeights($value)
    local $weights[11]=[1,2,4,8,16,32,64,128,256,512,1024]
    local $valuesArray[2]
    local $leftOver=$value

    for $a=UBound($weights)-1 to 0 step -1
        if $value>=$weights[$a] then
        $weightsValue=$weights[$a]
        ExitLoop
        EndIf
    Next
    $i=_arraySearch($weights,$weightsValue)

    do
    if $leftOver >=$weights[$i] then
        _ArrayPush($valuesArray,$weights[$i])
        $leftOver=$leftOver-$weights[$i]
        $i -=1
    Else
        $i-=1
        ContinueLoop
    EndIf
    until $leftOver=0

    _ArrayDisplay($valuesArray)
EndFunc

_getBinaryWeights(0x00000041)

 

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Share this post


Link to post
Share on other sites
Global $aPrintDriverAttribs[11][2]
$aPrintDriverAttribs[0][0] = 0x00000001
$aPrintDriverAttribs[0][1] = "PRINTER_DRIVER_PACKAGE_AWARE; "
$aPrintDriverAttribs[1][0] = 00000002
$aPrintDriverAttribs[1][1] = "PRINTER_DRIVER_XPS; "
$aPrintDriverAttribs[2][0] = 0x00000004
$aPrintDriverAttribs[2][1] = "PRINTER_DRIVER_SANDBOX_ENABLED; "
$aPrintDriverAttribs[3][0] = 0x00000008
$aPrintDriverAttribs[3][1] = "PRINTER_DRIVER_CLASS; "
$aPrintDriverAttribs[4][0] = 0x00000010
$aPrintDriverAttribs[4][1] = "PRINTER_DRIVER_DERIVED; "
$aPrintDriverAttribs[5][0] = 0x00000020
$aPrintDriverAttribs[5][1] = "PRINTER_DRIVER_NOT_SHAREABLE; "
$aPrintDriverAttribs[6][0] = 0x00000040
$aPrintDriverAttribs[6][1] = "PRINTER_DRIVER_CATEGORY_FAX; "
$aPrintDriverAttribs[7][0] = 0x00000080
$aPrintDriverAttribs[7][1] = "PRINTER_DRIVER_CATEGORY_FILE; "
$aPrintDriverAttribs[8][0] = 0x00000100
$aPrintDriverAttribs[8][1] = "PRINTER_DRIVER_CATEGORY_VIRTUAL; "
$aPrintDriverAttribs[9][0] = 0x00000200
$aPrintDriverAttribs[9][1] = "PRINTER_DRIVER_CATEGORY_SERVICE; "
$aPrintDriverAttribs[10][0] = 0x00000400
$aPrintDriverAttribs[10][1] = "PRINTER_DRIVER_SOFT_RESET_REQUIRED; "
Global $iPrinter = 0x000041
Global $sText = ""
For $i = 0 to UBound($aPrintDriverAttribs) - 1
    If BitAnd($iPrinter, $aPrintDriverAttribs[$i][0]) Then $sText = $sText & $aPrintDriverAttribs[$i][1]
Next
MsgBox(0, "Result", $sText)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks Jfish unfortunately your code would only return partial results, for example 0x0000000000000103 would only return results for "PRINTER_DRIVER_PACKAGE_AWARE; PRINTER_DRIVER_XPS;" but would leave out the results for "PRINTER_DRIVER_CATEGORY_VIRTUAL".  Thanks for trying though.

Water that works perfectly, I definitely need to learn how bitwise operations work, thanks for your help.

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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