program to write on unallocated space of hard-disk

E

erajaysharma

Hi,

Can some one please tell how can i write some data on sector 0 of a
hard disk...entire hard-disk is unallocated...

Thanks
Ajay
 
E

erajaysharma

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;
}
 
R

Roedy Green

Can some one please tell how can i write some data on sector 0 of a
hard disk...entire hard-disk is unallocated...

The DOS tools to write sector 0 are disabled in Vista out of security
concerns. They are too useful to viruses.
 
P

Pegasus \(MVP\)

Hi,

Can some one please tell how can i write some data on sector 0 of a
hard disk...entire hard-disk is unallocated...

Thanks
Ajay

You could boot the machine with a DOS boot disk and use
debug.exe to write data on sector 0.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top