Hi,
Can some one please tell how can i writesome data on sector 0 of ahard disk...entirehard-diskisunallocated...
Thanks
Ajay
I am using following program....but it is not working....it works if a
disk partition is allocated...
Device ID of that harddisk is physicaldrive1 and i am using following
program but CreateFile is always failing....
#define SIZE 512
int main()
{
DWORD dwBytesWrite=0;
unsigned char data[SIZE];
HANDLE hFloppy;
char drive[]="\\\\.\\physicaldrive1";
fstream inFile;
inFile.open("image.bin", ios::in | ios::binary);
if(inFile.fail())
{
printf("inFile not opened\n");
return 0;
}
inFile.read(data,SIZE);
inFile.close();
hFloppy = CreateFile(
drive,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_ALWAYS,
0,
NULL);
if(hFloppy == INVALID_HANDLE_VALUE)
{
DWORD Err = GetLastError();
printf("CreateFile failed : %d\n",Err);
}
if(!WriteFile(hFloppy, &data, SIZE,&dwBytesWrite, NULL))
{
printf("Write failed.\n");
return 0;
}
printf("dwBytesWrite: %d\n",dwBytesWrite);
return 0;
}