Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.7 KiB

  1. #include <nt.h>
  2. #include <ntddcdrm.h>
  3. #include <ntrtl.h>
  4. #include <nturtl.h>
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <process.h>
  8. #include <memory.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. int __cdecl
  13. main( int argc, char **argv )
  14. {
  15. BYTE DriveNameBuffer[32];
  16. HANDLE VolumeHandle;
  17. ULONG BytesTransferred;
  18. if( argc < 2 ) {
  19. printf( "usage: %s DriveLetter:\n", argv[0] );
  20. exit(4);
  21. }
  22. memset( DriveNameBuffer, 0, sizeof( DriveNameBuffer ) );
  23. strcat( DriveNameBuffer, "\\\\.\\" );
  24. strcat( DriveNameBuffer, argv[1] );
  25. // Open the volume with the DOS name.
  26. //
  27. VolumeHandle = CreateFile( DriveNameBuffer,
  28. GENERIC_READ,
  29. FILE_SHARE_READ | FILE_SHARE_WRITE,
  30. NULL,
  31. OPEN_EXISTING,
  32. 0,
  33. 0 );
  34. if( VolumeHandle == INVALID_HANDLE_VALUE ) {
  35. printf( "Unable to open %s [Error %d]\n",
  36. argv[1],
  37. GetLastError() );
  38. exit(4);
  39. }
  40. // GetFile information.
  41. //
  42. if( !DeviceIoControl( VolumeHandle,
  43. IOCTL_CDROM_REMOVE_DEVICE,
  44. NULL,
  45. 0,
  46. NULL,
  47. 0,
  48. &BytesTransferred,
  49. NULL ) ) {
  50. printf( "Unable to remove device [Error %d].\n", GetLastError() );
  51. CloseHandle( VolumeHandle );
  52. exit(4);
  53. } else {
  54. printf( "Removed %s\n", argv[1] );
  55. CloseHandle( VolumeHandle );
  56. return 0;
  57. }
  58. }