How to detect USB Wifi plug into computer via C#? - c#

I want to write a simple program that detect USB Wifi plugged computer and unplug it. I am finding code or library help me to do that (C# or Delphi). Tell me if you know :)
Or
Code or lib that list all USB devices on computer ?
Thanks !

I can only answer part of the question. You can "eject" USB devices using this API:
CM_Request_Device_Eject (MSDN link)
I'm using it to eject USB thumb drives after I copy stuff onto them in a backup application. I'm pretty sure there are ways of enumerating available USB devices using one of the many CM_XXX routines, but I was only interested in storage devices connected via USB, so I can't comment on WiFi devices.
An other sugestion: Maybe you can solve your problem at an other layer, maybe you can detect the addition of a new network adapter and disable that. Not all USB devices can be ejected, it's probably a driver-related issue. But I guess, if you can eject it from the notification area icon, you can eject it from code.

may have a look at http://sourceforge.net/projects/libusbdotnet/ (never used it by myself)

Related

Power cycling a USB device?

I'm working on troubleshooting a device that only works once it has been unplugged and plugged back into its USB port on the PC.
The application that talks to the device is written in C#. So I need a programmatic way in C# or perhaps batch files, etc. to reset a USB device.
Thus far I've tried using the devcon.exe tool, but that doesn't seem to do the same job that physically removing and adding it back does.
Is it possible to use Win32_USBController to control a USB device's power through the port somehow? MSDN Link
Perhaps in a similar fashion, I found the CIM_Controller class, which has Reset() function. MSDN Link
The tools for resetting a USB port in the Windows Driver Framework/Kit don't appear to be readily accessible via a library or otherwise without first creating an actual driver unless I'm mistaken.
Thanks
I would recommend that you navigate to the directory and find the device. Right click on it and in the short cut menu click on eject. The application and the OS should handle the device. It is a bad idea to "unplug" a USB device, especially flash drives without ejecting them. You could end up with open file errors.
If the problem is not ejecting the device then the issue is probably with the application. If the application is opening a file on the device and the device has to be unplugged in order to function properly then the application may not be closing the open file properly...
Just saying
You might look at the SO link: How to programmatically unplug & replug an arbitrary USB device?
and read through that...
it sounds to me like your scanner is completing a task then shutting it's post down. it remains plugged into the PC but the PC does not 'see' it. go to the directory and see if it is still in the directory...
unplugging once the device shuts down the port does nothing. replugging reconnects the electronics and the PC becomes aware of the device which completes one more task. then shuts down its port again.
Dr t

Uniquely identifying a pendrive

I am working on USB devices and can identify a usb device. But I have a theoretical question.Is it shows any usb device like portable cd drive or specifically flash drives? I could nt check all possibilities due to lack of these hardwares :). Is there any method to identify if it is a flash drive or another usb device.
Please don't beat with what you have tried. I googled regarding same but because of my least experience I couldn't find any.
Thanks
Please use the class USBSerialNumber
USBSerialNumber usb = new USBSerialNumber();
string serial = usb.getSerialNumberFromDriveLetter("f:\");
MessageBox.Show(serial);
Each pendrive has serial number which is unique.
You can use this class for this purpose.
Download it from following link:
http://www.cfdan.com/posts/Retrieving_Non-Volatile_USB_Serial_Number_Using_C_Sharp.cfm

Getting Info on NON_HID USB Device

How can I get details on NON-HID USB Devices? Like the serial number, etc in c#?
I have created successfully a sample application to retrieve those information on HID only devices but not on NON-HID USB Devices.
Have you looked into LibUSB .Net?
http://sourceforge.net/projects/libusbdotnet/
I remmber seeing that this was possible, I'll try and dig the article out.
You want to retrieve the device descriptors. Assuming a driver has been bound to the device, some of these are already available as they can be seen from Device Manager.

How to use computer's Bluetooth to send Wallpapers to any cellphone, in C#?

I'd like to know if it is possible how to do it, because my client asked me if the program I'm developing could also send wallpapers to nearby cellphones(my program will be in a place with many people passing by, so it would be good to have the bluetooth feature).
Thanks!
it can send pictures as files, users then may set them as wallpapers.
Unless the phone and the computer support bluetooth and are connected, you cannot. You can send the files to mobiles over bluetooth. 32feet provides a nice library to perform bluetooh related operations. Try that.
Hope it helps.
To do this you would need to
Make sure each user's device is paired to your bluetooth "sever"
Create the ability to auto connect and send the file.
On your phone's application, receive the image file and set the phone background - this will be different for each type of phone's OS. I would assume you are aiming towards Window Mobile Devices, since you are using c#.
The first step i see as being the difficult step as each phone much "register" the bluetooth of the server to be paired with it.

Connect and disconnect USB devices programmatically

I need to connect and disconnect USB devices, such as flash drives, in a programmatical manner, without unplugging and re-plugging the device.
Is there any way to do it in a C# Windows application?
You might want to look at some related questions:
Safe remove USB-Drive using Win32 API?
Windows - Power off an usb device in software
Both of the approaches mentioned in the answers are readily translatable to C#.

Categories

Resources