How Excel Resolves File Locking and User Identification on Network Shares: Technical Deep Dive


4 views

When working with Excel 2010 files on network shares, the file locking mechanism sometimes displays incorrect user information. Despite having proper usernames configured in Excel Options (File > Options > General > Personalize your copy of Microsoft Office), the system consistently shows one particular user as the lock holder regardless of who actually has the file open.

Excel employs a multi-layered approach to file locking:

1. Network share level locking (SMB protocol)
2. Excel application-level locking
3. Operating system user context

The username displayed comes from the File Lock Information (FLI) stored in the temporary lock file that Excel creates (typically with a ~$ prefix). This information is derived from:

  • The SMB session credentials
  • Excel's internal user identification
  • Windows security context

Here's a PowerShell script to check active file locks on your network share:

# PowerShell script to check locked files
$computer = "yourfileserver"
$sharePath = "\\$computer\sharedfolder"

Get-SmbOpenFile | Where-Object { $_.Path -like "$sharePath*" } | 
Select-Object ClientComputerName, ClientUserName, Path | Format-Table -AutoSize

Based on similar cases I've encountered, the issue typically stems from:

  1. Cached credentials: Windows might be using cached authentication
  2. Permission inheritance: The share might not properly reflect user changes
  3. Excel temporary files: Corrupted lock files maintaining stale information

Try these troubleshooting steps in order:

1. Clear Excel temporary files:
   del "%appdata%\Microsoft\Excel\*.xlb" /s /q
   del "%temp%\~$*.*" /s /q

2. Reset credential manager:
   cmdkey /list | ForEach-Object {cmdkey /delete:$_}

3. Verify share permissions:
   icacls "\\server\share" /reset /t /c /q

For system administrators dealing with frequent lock issues, here's a C# snippet to monitor Excel locks:

using System;
using System.IO;
using System.Management;

class ExcelLockMonitor {
    static void Main() {
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(
            "SELECT * FROM Win32_Process WHERE Name='EXCEL.EXE'");
            
        foreach (ManagementObject process in searcher.Get()) {
            string commandLine = process["CommandLine"]?.ToString();
            if (commandLine?.Contains(".xls") ?? false) {
                Console.WriteLine($"User: {process["ExecutablePath"]}");
                Console.WriteLine($"File: {commandLine}");
            }
        }
    }
}

To avoid recurring issues:

  • Implement document management systems instead of direct file sharing
  • Use SharePoint or Teams for collaborative editing
  • Upgrade to newer Excel versions (2016+) with improved locking mechanisms

When Excel 2010 locks files on network shares, it pulls user identification from unexpected system sources rather than Excel's own settings. Despite having correct names configured in Excel Options (File > Options > General > Personalize your copy of Microsoft Office), the lock message persistently displays one particular user.

Excel actually uses the Windows API's NetSessionEnum function to identify locking users. The precedence order is:

1. Active Directory (if domain-joined)
2. Local SAM database
3. Cached credentials
4. NetBIOS name resolution

When Excel consistently shows the wrong user, check these registry keys:

HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Common\UserInfo
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

A PowerShell script to audit these values:

# Check Office user info
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Office\14.0\Common\UserInfo" |
Select-Object UserName, UserInitials, UserLCID

# Verify Windows authentication defaults
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" |
Select-Object DefaultUserName, DefaultDomainName

The issue often stems from credential caching. Clear stale entries with:

net use * /delete /y
klist purge

For situations requiring immediate resolution, this VBA macro forces Excel to refresh user identity:

Sub RefreshExcelIdentity()
    Dim netPath As String
    netPath = "\\server\share\locked_file.xlsx"
    
    On Error Resume Next
    Workbooks.Open netPath, ReadOnly:=True
    If Err.Number = 1004 Then
        MsgBox "File locked by: " & Err.Description
    End If
    On Error GoTo 0
End Sub

Create a Group Policy to enforce proper credential delegation:

Computer Configuration > Policies > Administrative Templates > System > Credentials Delegation:
- Enable "Allow Delegating Default Credentials"
- Add servers to "Add servers to the list"