An "ERROR_ACCESS_DENIED" error occurs when you try to write to a file that is in a network shared folder

기술 자료 번역 기술 자료 번역
기술 자료: 842792 - 이 문서가 적용되는 제품 보기.
Important This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:
256986Description of the Microsoft Windows Registry
모두 확대 | 모두 축소

이 페이지에서

현상

A call to the WriteFile function may not succeed. You experience this symptom when the following conditions are true:
  • You are using a client computer that is running Microsoft Windows XP Service Pack 1 (SP1).
  • You use the WriteFile function to try to write to a file that is in a network shared folder.
  • The shared folder is on a server computer that is running either Microsoft Windows 2000 or Microsoft Windows Server 2003.
Additionally, you may receive the following error message:
ERROR_ACCESS_DENIED

원인

This problem occurs when the following conditions are true:
  • When you used the CreateFile function to create the file, you specified only the GENERIC_WRITE constant in the dwDesiredAccess parameter.
  • Server Message Block (SMB) signing is enabled for communication between the client computer and the server computer.

해결 과정

To work around this problem, use either of the following methods:
  • Specify the GENERIC_READ constant and the GENERIC_WRITE constant in the dwDesiredAccess parameter.
  • Modify SMB signing.

Specify the GENERIC_READ constant and the GENERIC_WRITE constant in the dwDesiredAccess parameter

Use the following code to create the file.

Note Replace the following placeholders:
  • Replace the ServerName placeholder with the name of a server computer that is running Windows 2000 or Windows Server 2003.
  • Replace the FolderName placeholder with the name of a network shared folder on the server computer.
// Specify the GENERIC_READ constant and the GENERIC_WRITE constant
// in the dwDesiredAccess parameter when you create the file.
hFile = CreateFile("\\\\ServerName\\FolderName\\Test.txt", GENERIC_READ |
    GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

Modify SMB signing

Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.
Follow these steps on the server computer and on the client computer:
  1. In Registry Editor, locate and then click the following registry subkey:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Lanmanserver\Parameters
  2. In the right pane of Registry Editor, right-click requiresecuritysignature in the Name field, and then click Modify. The Edit DWORD Value dialog box appears.
  3. In the Value data box, type 0, and then click OK.
  4. Quit Registry Editor, and then restart the computer.

추가 정보

Steps to reproduce the behavior

  1. On a computer that is running Windows XP SP1, use Microsoft Visual C++ 6.0 to create a simple Win32 Console Application project that is named Test. By default, the Test.cpp file is created.
  2. Create a file by specifying only the GENERIC_WRITE constant in the dwDesiredAccess parameter when you use the CreateFile function.
  3. Use the WriteFile function to try to write to the file. To do this, replace the existing code in the Test.cpp file with the following code.

    Note Replace the following placeholders:
    • Replace the ServerName placeholder with the name of a server computer that is running Windows 2000 or Windows Server 2003.
    • Replace the FolderName placeholder with the name of a network shared folder on the server computer.
    :
    #include "stdafx.h"
    #include "windows.h"
    #include "stdio.h"
    #include "conio.h"
    
    void main()
    {
        HANDLE hFile;
        char lpBuffer[99999];
        DWORD lpNumberOfBytesWritten;
    
        // Write data to the buffer that you will
        // you use to write data to the file.
        for (int i = 0; i < 100000; ++i)
            lpBuffer[i] = 'a';
    
        // Specify only the GENERIC_WRITE constant in the
        // dwDesiredAccess parameter when you create the file.
        hFile = CreateFile("\\\\ServerName\\FolderName\\Test.txt",
            GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    
        // Try to write the data in the buffer to the file.
        // If the call to the WriteFile function fails,
        // call the GetLastError function.
        if (!WriteFile(hFile, lpBuffer, 100000, &lpNumberOfBytesWritten, NULL))
    
            // If an ERROR_ACCESS_DENIED error has occurred, inform the user.
            if (GetLastError() == ERROR_ACCESS_DENIED)
            {
                printf("An ERROR_ACCESS_DENIED error has occurred.");
                printf("Press any key to continue.");
                getch();
            }
    
        // Close the handle to the file.
        CloseHandle(hFile);
    }
  4. Build and then run the application. A console window appears. If the behavior that is mentioned in the "Symptoms" section occurs, the console window contains the following output:
    An ERROR_ACCESS_DENIED error has occurred.
    Press any key to continue.

참조

For more information about the CreateFile function and the WriteFile function, visit the following Microsoft Developer Network (MSDN) Web sites:
CreateFile
http://msdn2.microsoft.com/en-us/library/aa363858.aspx
WriteFile
http://msdn2.microsoft.com/en-us/library/aa365747.aspx

속성

기술 자료: 842792 - 마지막 검토: 2007년 1월 17일 수요일 - 수정: 1.5
본 문서의 정보는 다음의 제품에 적용됩니다.
  • Microsoft Windows XP Professional SP1?을(를) 다음과 함께 사용했을 때
    • Microsoft Windows Server 2003, Standard Edition (32-bit x86)
    • the operating system: Microsoft Windows 2000
  • Microsoft Windows XP Home Edition SP1?을(를) 다음과 함께 사용했을 때
    • Microsoft Windows Server 2003, Standard Edition (32-bit x86)
    • the operating system: Microsoft Windows 2000
키워드:?
kbmt kbclient kbprb kberrmsg kbregistry kbkern32dll kbapi kbsmb kbserver KB842792 KbMtko
기계 번역된 문서
중요: 본 문서는 전문 번역가가 번역한 것이 아니라 Microsoft 기계 번역 소프트웨어로 번역한 것입니다. Microsoft는 번역가가 번역한 문서 및 기계 번역된 문서를 모두 제공하므로 Microsoft 기술 자료에 있는 모든 문서를 한글로 접할 수 있습니다. 그러나 기계 번역 문서가 항상 완벽한 것은 아닙니다. 따라서 기계 번역 문서에는 마치 외국인이 한국어로 말할 때 실수를 하는 것처럼 어휘, 구문 또는 문법에 오류가 있을 수 있습니다. Microsoft는 내용상의 오역 또는 Microsoft 고객이 이러한 오역을 사용함으로써 발생하는 부 정확성, 오류 또는 손해에 대해 책임을 지지 않습니다. Microsoft는 이러한 문제를 해결하기 위해 기계 번역 소프트웨어를 자주 업데이트하고 있습니다.

피드백 보내기

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com