• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1693
  • Last Modified:

DELETE master boot record

Hi,

I was try this sample the delete a master boot of my secodary HD.

hDevice = CreateFile("\\.\E:", 0, FILE_SHARE_READ Or FILE_SHARE_WRITE, null, CREATE_ALWAYS, 0, 0);

result = DeviceIoControl(hDevice, IOCTL_DISK_DELETE_DRIVE_LAYOUT, null, 0&, null, 0&, bytesReturned, null);

(I was translate this code from VB6 to C++)


but not work and after the secord line the function GetLastError return 'access denited' . What can i do to have access to this operation ?
0
Marco_Panza
Asked:
Marco_Panza
  • 10
  • 10
1 Solution
 
jkrCommented:
The problem is that you cannot do that with the disk you booted from, since that one is considered to be 'in use'...
0
 
grg99Commented:
At the very least you need to double-up all your backslashes.

Also The system may not let you delete the MBR on a mounted disk.

If you absolutely must do this, which is unlikely, you might do it through the old 16-bit BIOS calls.



0
 
Marco_PanzaAuthor Commented:
If with this function is not possible , what can I do to erase the master boot or partition ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jkrCommented:
You won'be able to do that for a system that is up and running. The above I/O control code can do that to a secondary disk, but not for the one the system was booted from. You might be able to run that from a NTFS bootdisk, but...
0
 
Marco_PanzaAuthor Commented:
I was try to delete the partition on drive F: (not primary disk).
0
 
jkrCommented:
Just a side note - the call should be

DWORD bytesReturned;

result = DeviceIoControl(hDevice, IOCTL_DISK_DELETE_DRIVE_LAYOUT, NULL, 0, NULL, 0, &bytesReturned, NULL);

Apart from that, if the partition is formatted, you should try to 'FSCTL_DISMOUNT_VOLUME' beforehand.
0
 
Marco_PanzaAuthor Commented:
excuse me: what are the function  DISMOUNT VOLUME .My probem is:

I was try find the way for delete one partition because after this operation I will clone a disk.I have already a code for clone the disk but not work fine because some sector are protected by operation system.I think: if I delete the partition (some program like 'R-DriveImage' delete first the partition and after clone the disk) my code work fine.

What you think ?
0
 
jkrCommented:
I was thinking of

result = DeviceIoControl(hDevice, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &bytesReturned, NULL);
result = DeviceIoControl(hDevice, IOCTL_DISK_DELETE_DRIVE_LAYOUT, NULL, 0, NULL, 0, &bytesReturned, NULL);
0
 
Marco_PanzaAuthor Commented:
Jkr

If I try to use FSCTL_LOCK_VOLUME the operation system don't have a control to disk because the drive is locked.If I try to clone it after the call FSCTL_LOCK_VOLUME.What you think ?
0
 
jkrCommented:
It shouldn't be necessary to lock the volume. BTW, you might find the following discussion interesting: http://groups.google.de/groups?hl=de&lr=&frame=right&th=94cff24c836f7e57&seekm=3E96F3DC.D09E553F%40paragon.ru#link1
0
 
Marco_PanzaAuthor Commented:
OK ,

For me this is the right way !!

Can you find a value for this constants  IOCTL_DISK_SET_DRIVE_LAYOUT ,  FSCTL_DISMOUNT_VOLUME ?
0
 
jkrCommented:
Sure, that is

#define FSCTL_DISMOUNT_VOLUME           CTL_CODE(FILE_DEVICE_FILE_SYSTEM,  8, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_DISK_SET_DRIVE_LAYOUT     CTL_CODE(IOCTL_DISK_BASE, 0x0004, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)

or in simple numeric values:

IOCTL_DISK_SET_DRIVE_LAYOUT:    507920 (0x0007c010)
FSCTL_DISMOUNT_VOLUME:  589856 (0x00090020)
0
 
Marco_PanzaAuthor Commented:
I test it but not work:

(This is the VB6 code)

hDevice = CreateFile("\\.\F:", 0&, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0&, 0&)
             
result = DeviceIoControl(hDevice, FSCTL_DISMOUNT_VOLUME, ByVal 0&, 0&, ByVal 0&, 0&, bytesReturned, ByVal 0&)

GetLastError return code 1 (function not correct) and result = 0
0
 
jkrCommented:
Is 'hDevice' valid?
0
 
Marco_PanzaAuthor Commented:
Yes is 987
0
 
jkrCommented:
Hmm, that would indicate that the FS driver does not support that. What filesystem is it?
0
 
Marco_PanzaAuthor Commented:
NTFS with XP professional
0
 
Marco_PanzaAuthor Commented:
OK I was solved !!!!

The GENERIC_READ AND GENERIC_WRITE are missing.I wating for the function IOCTL_DISK_DELETE_DRIVE_LAYOUT finish. FSCTL_DISMOUNT_VOLUME work fine.
0
 
jkrCommented:
OK, great! Well, can happen, I don't speak any VB and proabaly missed that :o)
0
 
Marco_PanzaAuthor Commented:
jkr

I like to offer you a FREE licenze of the follow software.

www.pro-software.it/pro_email_sender.exe (newsletter sender)
www.pro-software.it/syncronize_backup_1.0.exe (Backup software)

After install give me a serial number and after I will send you the activation key to register.

Thanks for all !!!!!!!!!!!!!!!!!
0
 
jkrCommented:
Thanx, but I don't really need to send out newsletters and 'tar' works just fine on pur servers :o)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 10
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now