BUG: CreateFile with OPEN_ALWAYS Sets Last Error Incorrectly
Article ID: 194929
Article Last Modified on 3/3/2005
APPLIES TO
- Microsoft Win32 Application Programming Interface, when used with:
- Microsoft Windows NT Advanced Server 3.1
- Microsoft Windows NT 3.51 Service Pack 5
- Microsoft Windows 2000 Standard Edition
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.
Keywords: kbbug kbkernbase kbpending kbfileio KB194929