Jump to content

How to return configured flags from an attribute?


Subz
 Share

Recommended Posts

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; "

 

Link to comment
Share on other sites

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

Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

Link to comment
Share on other sites

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...