#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);
}