3 Replies - 1348 Views - Last Post: 08 December 2008 - 03:00 PM Rate Topic: -----

#1 AntiBNI   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 21-July 06

USB Dismount not turning off my USB Drive?

Post icon  Posted 08 December 2008 - 09:32 AM

I'm making an app that needs to safely remove USB Drives and SD cards.

When i execute my code,the drive gets forced not to be ready.

I have an old 128MB usb drive and when i start transferring data to it and execute my code,a msg box pops up saying: USB Cannot copy to "FileName" Device not ready.

And also,when i execute the code the drive stays visible in the pc and can be accessed again without having to replug.

Is that normal?
Am i doing some thing wrong?
Am i missing something?

Heres my code:
HANDLE File;
	DWORD BytesReturned;
	char DrivePath[MAX_PATH] = "\\\\.\\J:";
	File = CreateFile(DrivePath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
	DeviceIoControl(File,FSCTL_LOCK_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
	DeviceIoControl(File,FSCTL_DISMOUNT_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
	DeviceIoControl(File,IOCTL_STORAGE_MEDIA_REMOVAL,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
	DeviceIoControl(File,FSCTL_UNLOCK_VOLUME,NULL,NULL,NULL,NULL,&BytesReturned,NULL);
	CloseHandle(File);
		if(&BytesReturned == 0)
		MessageBox("The Drive Could Not be Removed,Is being used by an app or has not finished an operation","Note",MB_OK);
		else
		MessageBox("You can now remove the USB Drive","Removed",MB_OK);




Help will be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: USB Dismount not turning off my USB Drive?

#2 Desiredefx   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 24-October 08

Re: USB Dismount not turning off my USB Drive?

Posted 08 December 2008 - 10:31 AM

Quote

And also,when i execute the code the drive stays visible in the pc and can be accessed again without having to replug.


However I wont be able to help you with the coding portion of this due to my limited knowledge but I can let you know why this is happening, when you access flash memory on your pc, it stores the device into registry, what you will need to do in your code is do delete the registry value of the device to properly remove it, and not have it stay visible in the pc.[/end run on sentence]

This post has been edited by Desiredefx: 08 December 2008 - 10:32 AM

Was This Post Helpful? 0
  • +
  • -

#3 AntiBNI   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 21-July 06

Re: USB Dismount not turning off my USB Drive?

Posted 08 December 2008 - 11:55 AM

Oh,I will find a bit of info on that and check in my registry.


Thanks for that info,it is appreciated.

This post has been edited by AntiBNI: 08 December 2008 - 02:59 PM

Was This Post Helpful? 0
  • +
  • -

#4 AntiBNI   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 63
  • Joined: 21-July 06

Re: USB Dismount not turning off my USB Drive?

Posted 08 December 2008 - 03:00 PM

I can't Find the Registry key to disable the drive.

All i can find is how to disable read/write of all USB drives,and that's not what i am looking for.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1