English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i want to find out when usb drive is attached/detached from the pc. any ideas in c#.net or vb.net will be prefered

2006-07-11 05:53:21 · 2 answers · asked by faraz 1 in Computers & Internet Programming & Design

2 answers

You should use the filesystem object.
Because what the other person answer is only correct if you did not attach a other usb device to that slot. Give the device a specific name and then left the filesystem loop trough the drives looking if he find a device with that name

Helmut

2006-07-11 06:18:49 · answer #1 · answered by hswes 2 · 0 0

Well, either .Net language you want to use it's up to you. Basically you should set a variable and have it as a Boolean once you do that. You design code to search for the letter drive. Like example how you load files or list the contents of drive C: find out what the drive letter is for your USB mine is a flash drive and is always drive F: so basically you make code that is If driveF = True then...... End IF I think that be the best way to make a switch a quick fix would be load a text file on to your USB drive and if it cannot access it then. Obviously, the drive isn't attached this raises the issue though. If, the text file is deleted by mistake then your code is worthless. But, there are many different commands in .Net to access drives. Unless your using arrays to store data in that case you should learn how to stream to text and load text into your program first.

--------Update-----
Well, if you make a line of code that searches to see if it can find the text file on the usb drive. If, it doesn't find this text file then it will come back as false which means it the drive usb drive is detached. So, this does work because if it finds the text file then it comes back true. Meaning your usb drive is attached. This, is just a quick and easy fix but sometimes simple code like this works a lot quicker than complex code. Plus, with a usb drive when you have it pluged I have two drives and reguardless of the usb slot you put them in they always come in as the same letter drives.

2006-07-11 13:06:27 · answer #2 · answered by groundbrandon 3 · 0 0

fedest.com, questions and answers