Windows: How do I get the mode/access rights of an already opened file?

后端 未结 3 2057
旧时难觅i
旧时难觅i 2020-12-06 15:53

I am writing a program that is using a database library. The library provides me access to the file handle it uses to access my table. I\'ve found a windows API that allows

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 16:03

    OK. So I finally got this part all figured out - thanks to your direction, a lot of MSDN study and a LOT of trial and error.

    There were a couple of tricky points to getting this all figured out.

    1) The ACCESS_MASK certainly did not reflect the access modes as I expected. The documentation led me to expect the upper 4 bits to reflect the "GENERIC" modes that I opened the file with - wrong! Those show up in the Specific Rights section. Heck - I still don't have a clue when those upper 4 bits actually get used, but for this exercise I don't need to.

    2) Once I got THAT clear in my mind I had to stumble across documentation that let me know that when I opened with GENERIC_READ that was translated into:

    FILE_GENERIC_READ

    which is made up of:

    STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA | SYNCHRONIZE

    Understanding this concept made all the rest of it fall into place. Now my understanding correlated with the information that Process Hacker was telling me.

    3) I also had a serious error going from my UI to the code (read one constant misplaced), which once figured out made the whole world lay down before my feet.

    This is great because I can now figure out what Access Modes were used when the file was opened. Original question answered!

    Now I would like to be able to determine the "share" mode the file is in - if possible. Any ideas?

    Thanks again for your help

提交回复
热议问题