?
Solved

DELETE master boot record

Posted on 2005-03-18
21
Medium Priority
?
1,582 Views
Last Modified: 2010-08-05
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
Comment
Question by:Marco_Panza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 10
21 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 13575787
The problem is that you cannot do that with the disk you booted from, since that one is considered to be 'in use'...
0
 
LVL 22

Expert Comment

by:grg99
ID: 13575858
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
 

Author Comment

by:Marco_Panza
ID: 13576589
If with this function is not possible , what can I do to erase the master boot or partition ?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:jkr
ID: 13576629
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
 

Author Comment

by:Marco_Panza
ID: 13577747
I was try to delete the partition on drive F: (not primary disk).
0
 
LVL 86

Expert Comment

by:jkr
ID: 13577835
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
 

Author Comment

by:Marco_Panza
ID: 13577919
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
 
LVL 86

Expert Comment

by:jkr
ID: 13578036
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
 

Author Comment

by:Marco_Panza
ID: 13578666
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
 
LVL 86

Expert Comment

by:jkr
ID: 13578783
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
 

Author Comment

by:Marco_Panza
ID: 13578971
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
 
LVL 86

Expert Comment

by:jkr
ID: 13579040
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
 

Author Comment

by:Marco_Panza
ID: 13579124
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
 
LVL 86

Expert Comment

by:jkr
ID: 13579137
Is 'hDevice' valid?
0
 

Author Comment

by:Marco_Panza
ID: 13579156
Yes is 987
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 13579191
Hmm, that would indicate that the FS driver does not support that. What filesystem is it?
0
 

Author Comment

by:Marco_Panza
ID: 13579201
NTFS with XP professional
0
 

Author Comment

by:Marco_Panza
ID: 13579444
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
 
LVL 86

Expert Comment

by:jkr
ID: 13580282
OK, great! Well, can happen, I don't speak any VB and proabaly missed that :o)
0
 

Author Comment

by:Marco_Panza
ID: 13581422
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
 
LVL 86

Expert Comment

by:jkr
ID: 13584430
Thanx, but I don't really need to send out newsletters and 'tar' works just fine on pur servers :o)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question