how to safely remove usb in vb.net?

  • Thread starter prism via DotNetMonster.com
  • Start date
P

prism via DotNetMonster.com

question: how do we safely remove a USB device in vb.net?

for example, in the vb.net application, we open some files from a usb device,
and after that, we want to "safely remove" it without doing it manually from
the taskbar.

how do we do it? can anyone help me?
 
A

Armin Zingler

prism via DotNetMonster.com said:
question: how do we safely remove a USB device in vb.net?

for example, in the vb.net application, we open some files from a
usb device, and after that, we want to "safely remove" it without
doing it manually from the taskbar.

how do we do it? can anyone help me?


VB does not have a keyword for this. VB.Net offers access to managed
assemblies and native dlls (platform invoke). Ask in a framework group, look
for a tool/library or in the MSDN library win32 section.


Armin
 
P

prism via DotNetMonster.com

VB does not have a keyword for this. VB.Net offers access to managed
assemblies and native dlls (platform invoke). Ask in a framework group, look
for a tool/library or in the MSDN library win32 section.

Armin


ok. thanks for the tip!
 
R

RDub

I had this same issue with a VB6 app I developed. I solved it by shelling
to an external program deveject.exe I found here
ftp://ftp.heise.de/pub/ct/listings/0316-208.zip The archive comes with the
C source code so you can reverse-engineer it to run native if you have the
time. For my purpose it was enough to put the tiny (44Kb) command line
application in the same directory as my app and just shell() to it with the
appropriate command line args. I had spent nearly an entire day writing
code that almost worked before I stumbled across deveject. Had deveject
working in my app, and all of the "almost working code" deleted in 10
minutes, haven't looked back since.

Ron W
 
K

kimiraikkonen

question: how do we safely remove a USB device in vb.net?

for example, in the vb.net application, we open some files from a usb device,
and after that, we want to "safely remove" it without doing it manually from
the taskbar.

how do we do it? can anyone help me?

You may want to open safe remove dialog by putting this command into a
system.diagnostics.process.start area.

System.diagnostics.process.start("RunDll32.exe
shell32.dll,Control_RunDLL hotplug.dll")

Please let us know if it works or not.

Regards.
 
K

kimiraikkonen

You may want to open safe remove dialog by putting this command into a
system.diagnostics.process.start area.

System.diagnostics.process.start("RunDll32.exe
shell32.dll,Control_RunDLL hotplug.dll")

Please let us know if it works or not.

Regards.

Addition: If it doesn't work try putting it into Shell follows:

Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")

Regards.
 
K

kimiraikkonen

Addition: If it doesn't work try putting it into Shell follows:

Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")

Regards.

I tried and verified, this works and opens safe remove dialog.

Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")

Hope i helped.

Regards.
 
P

prism via DotNetMonster.com

kimiraikkonen said:
[quoted text clipped - 22 lines]

I tried and verified, this works and opens safe remove dialog.

Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")

Hope i helped.

Regards.


WOW!! it really works! thanks!!

is there a way to cuztomize the "safely remove" in a way that it can remove a
specific drive?
 
K

kimiraikkonen

[quoted text clipped - 22 lines]
I tried and verified, this works and opens safe remove dialog.
Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")
Hope i helped.

WOW!! it really works! thanks!!

is there a way to cuztomize the "safely remove" in a way that it can remove a
specific drive?

Glad to help. This method only works for opening Windows's standard
safe remove dialog directly. Maybe there should be an API call or
control may help which i don't know.

Regards.
 
P

prism via DotNetMonster.com

kimiraikkonen said:
[quoted text clipped - 22 lines]

I tried and verified, this works and opens safe remove dialog.

Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")

Hope i helped.

Regards.


hi! it's me again! i just wanna ask when i play my vb program and when i open
a file from the usb in the openfiledialog , in windows xp why cant it be
safely removed? it will say it cant be stopped.. but in vista, it can be
safely removed.
 
K

kimiraikkonen

[quoted text clipped - 22 lines]
I tried and verified, this works and opens safe remove dialog.
Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")
Hope i helped.

hi! it's me again! i just wanna ask when i play my vb program and when i open
a file from the usb in the openfiledialog , in windows xp why cant it be
safely removed? it will say it cant be stopped..  but in vista, it can be
safely removed.

Hi,
There may be other reasons, but the closest reason is to me is your vb
program or the file/component associated with your vb program is still
in use.

Assuming you're using same code/program on both operating systems,
make sure you close/dispose your program's resources properly using
correct syntax (i recommend "using-end using" statement for auto
resource disposal in your code block).

Another reason maybe that another program is accessing the file which
is used by your vb app, that maybe the reason of failure of a safe-
removal because of multi-usage. For example some storage related 3rd
party apps and their services can cause that problem such as SMART
monitor programs, antivirus trackers, system tools etc.

Don't know much about VB's behaviours on Vista, but the logic must be
same. Make sure you are running 1:1 same programs on background on XP
and Vista to have a more proper test. There may be extra programs that
causing the problem on XP.

Hope this helps.

Regards...
 
K

kimiraikkonen

[quoted text clipped - 22 lines]
I tried and verified, this works and opens safe remove dialog.
Shell("RunDll32.exe shell32.dll,Control_RunDLL hotplug.dll")
Hope i helped.

hi! it's me again! i just wanna ask when i play my vb program and when i open
a file from the usb in the openfiledialog , in windows xp why cant it be
safely removed? it will say it cant be stopped..  but in vista, it can be
safely removed.

Additionaly, you can take a look at this:
http://safelyremove.com/faq.htm
http://ask-leo.com/why_do_i_get_dev...now_trying_to_safely_remove_my_usb_drive.html

Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top