Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


About EjectDiskFromSADrive function

Posted on 2004-10-28
Medium Priority
Last Modified: 2008-01-16
i'd like a word or two about how to use this function EjectDiskFromSADrive.
I am trying to eject my cdrom drive simply using the following code, ALTHOUGH i am not really confident that i am doing it right.I'd like to know if this is the function to use to eject the cdrom and how to use it right.

int main()
DWORD ret = 0;
ret = EjectDiskFromSADrive( NULL, NULL, "\\.\\Cdrom0", NULL, NULL, NULL, NTMS_EJECT_FORCE );
case ERROR_ACCESS_DENIED: printf("NTMS_CONTROL_ACCESS to the library is denied. Other security errors are also possible, but they would indicate a security subsystem error."); break;
case ERROR_DATABASE_FAILURE: printf("The database is inaccessible or damaged."); break;
case ERROR_DATABASE_FULL: printf("The database is full."); break;
case ERROR_DEVICE_NOT_AVAILABLE: printf("The library is disabled."); break;
case ERROR_INVALID_HANDLE: printf("The session ID is invalid or missing."); break;
case ERROR_INVALID_OPERATION: printf("A stop was performed on an invalid operation ID."); break;
case ERROR_INVALID_PARAMETER: printf("A library ID or operation ID pointer is missing."); break;
case ERROR_LIBRARY_OFFLINE: printf("The library ID refers to an offline library that cannot eject media."); break;
case ERROR_MEDIA_NOT_AVAILABLE: printf("The media is disabled."); break;
case ERROR_NOT_ENOUGH_MEMORY: printf("There was an allocation failure during processing."); break;
case ERROR_SUCCESS: printf("The eject operation was successful."); break;

return 0;

I always get the ERROR_INVALID_PARAMETER error.
I'd like some help. the msnd is not very helpful.

Question by:skiritis13
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
  • 3
  • 3
LVL 86

Expert Comment

ID: 12438259

That should be


Thus the 'invalid parameter' error. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/devio/base/ejectdiskfromsadrive.asp ("EjectDiskFromSADrive"):

[in] Name of the device to eject. For example, \\.\Cdrom0 or \\.\PhysicalDriveX (where X is the number of the drive being accessed).

As backslashes need to be doubled, "\\\\.\\Cdrom0" is the correct value.

Author Comment

ID: 12438753
sorry to break it to you but i already did that.
the results are the same. the 4 backslashes doesn't change something.
so i'm back at the same point.
LVL 86

Expert Comment

ID: 12440826
Um, and have you tried supplying the dialog box parameters that you st to NULL? I.e.:

    [in] Handle to a dialog box window for user confirmation.
    [in] Title displayed in a dialog box to get user input.
    [in] Message displayed in a dialog box to get user input.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 12442830
Still no luck even if i change tha params to  this

EjectDiskFromSADrive( NULL, NULL, "\\\\.\\Cdrom0", NULL, "Title", "Message", NTMS_EJECT_FORCE );

I do not think the hWnd param should be sth other than NULL because that just means that the desktop owns the Messagebox.

Any help from anyone???
I'm increasing the points.
LVL 86

Accepted Solution

jkr earned 200 total points
ID: 12447443
>>I do not think the hWnd param should be sth other than NULL

No, the docs *explicitly* state "Handle to a dialog box window for user confirmation"

Author Comment

ID: 12452459
OK i hear you...
Now i get the same error using the function like this:

DWORD ret = 0;
HWND hwnd = GetDesktopWindow();
ret = EjectDiskFromSADrive( NULL, NULL, "\\\\.\\Cdrom0", hwnd, "Eject", "Eject", NTMS_EJECT_FORCE );

LVL 19

Assisted Solution

BrianGEFF719 earned 200 total points
ID: 12516710
Have you Considered EjectNtmsMedia??


I think this might work better for you.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

610 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