BUG: CreateFile with OPEN_ALWAYS Sets Last Error Incorrectly (194929)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows NT 3.1
    • the operating system: Microsoft Windows NT 3.51
    • the operating system: Microsoft Windows NT 4.0
    • the operating system: Microsoft Windows 2000

This article was previously published under Q194929

SYMPTOMS

If you call the CreateFile API with the OPEN_ALWAYS flag when the specified file already exists, the API should return a valid handle and GetLastError should return ERROR_ALREADY_EXISTS.

When the file that is being opened is being accessed using either a UNC path name or through a mapped drive, GetLastError sometimes returns ERROR_SUCCESS even if the file already exists.

RESOLUTION

Break up the CreateFile call with the OPEN_ALWAYS flag into two separate calls to CreateFile.

Call CreateFile with the OPEN_EXISTING flag. If the call to CreateFile succeeds, the file already existed. If the call to CreateFile fails, you can call CreateFile with the OPEN_ALWAYS flag.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

MORE INFORMATION

This error only occurs if the file is being accessed using either a UNC path name or through a mapped drive and the file is located on a Windows NT Server.

Modification Type:MinorLast Reviewed:3/3/2005
Keywords:kbbug kbFileIO kbKernBase kbpending KB194929