Excel Lock File - Why can i copy it, but not open it?

1

If i have an Excel file SomeFile.xlsx open, a file is created ~SomeFile.xlsx that contains the name of the user who has opened/locked the Excel file. I can't directly open the file in Notepad, but I can copy it and then open the copy.

If the file can be copied then obviously it can be opened for read access. So why can't I just open it in Notepad?

3-14159265358979323846264

Posted 2019-11-01T12:29:37.903

Reputation: 83

Answers

2

This is because of windows' File Locking mechanism:

File locking is a mechanism that restricts access to a computer file by allowing only one user or process to access it in a specific time. Systems implement locking to prevent the classic interceding update scenario, which is a typical example of race condition, by enforcing the serialization of update processes to any given file

Normally, you should not be able even see this hidden file (unless you change the default settings). You can copy the locked file, which stay hidden but can now be open for write / read access.

duDE

Posted 2019-11-01T12:29:37.903

Reputation: 14 097

1Cheer duDE! So does that mean there's a low level API that will let me read the file without copying it first? – 3-14159265358979323846264 – 2019-11-01T13:11:37.433

Sure, the Win32API: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-unlockfile

– duDE – 2019-11-01T13:27:24.933

So is that the method Windows Explorer uses when it copies a file? UnlockFile > Read > Write > (Relock?). – 3-14159265358979323846264 – 2019-11-01T13:39:49.223

With high probability that is it ;) – duDE – 2019-11-01T13:44:50.613