0

What software can I use to detect the details of how a file is opened (specifically permissions for other processes)?

We have two versions of card printing software: CardFive, and Zebra Card Studio which acquired CardFive and maintains their old software.

Both open a CSV file for printing instructions. The old version allows subsequent instances of the software to modify those instructions. The new version does not -- it refuses to allow any modification.

I suspect the problem is with the file locking privileges, i.e. the old software opens with OF_SHARE_DENY_NONE (ReadWrite in .NET's FileShare Enumeration), and that the new software opens with greater share restrictions.

How can I tell exactly how a network file is locked? I tried looking at multiple instances of both application versions in Process Explorer, but it shows only which process has a file open -- not how it is open: enter image description here

enter image description here

I am aware that concurrent write access can cause data integrity issues. In this specific case, I do not expect that to be a problem.

0

File locking on Windows happens on two levels. A program can lock the entire file (CreateFile API) or a region of it (LockFileEx API). The Windows API (Win32) does not provide a standard way to figure out how a file was opened. The API NtQueryObject can provide some information about how the file was opened, but it does not include sharing requirements and it is an internal API which might change at any time.

However, an application can approximate the sharing semantics of an open file by trying to open it and checking when opening fails due to denied access. Such a program would try to open a file for (1) no access, then (2) reading access, then (3) writing access. An application can then check if there are any regions of the file that are locked by trying to lock regions of it.

The problem with this method is that it might interfere with the application that is actively using the file in question and might lead it to fail.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.