C# Check if Usb Drive is removable - c#

I write Files on a USB Drive and sometimes i have a bug where the popup of end of files transfert is displayed before the export is successful, therefore the user unplug the key too soon.
So have you a solution to check if the usb drive is in use or is safe for remove?
Thanks
I try to understand why the pop-up is showing to soon but I find no reason.
For the moment my solution is to try to Open the last copied file with file.open() and try catch but I'm not satisfied of this solution.

Related

Autorun.inf don't work and I can't run c# exe

I am Adel and I am creating an program and I want to save it into an USB and auto run it whenever the USB is inserted to any Windows device, the problem is that the code that I use in Autorun.inf doesn't work.
The files in the correct path and the Autorun.inf file in the root of the USB, but it's not working!
NOTE: the exe also works
The code:
[Autorun]
Icon=USBSYS\icon.ico
open=USBSYS\file.exe
action=MyUSBName
Label=MyUSBName
Autorun.inf does not work anymore on USB drives. Its a security thing to prevent people from putting malicious programs on a thumb drive. It does work on CDs/DVDs though.

How to access dev folder in android?

I'm making android app through Unity, which will access and read data output from serial device, connected through USB cable to tablet. I have everything figured out except one thing.
When I try APP on tablet it throws UnauthorizedAccessException: Access to the path "/dev" is denied.
How can I grant access to this directory without rooting tablet ? I dont think I need because i tried other APP from Google Play to read from my serial device and it works great.
Can you help me with this ? I hope for some "grant permission in manifest xml" tip or something. I searched a lot but nothing fits my case...

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

How do I check programmatically whether a network drive has been mapped?

Currently I'm using System.IO.Directory.Exists("Z:\\") to check. However, it still returns true even after I have disconnected the network drive using File Explorer. It also still returns true after I have mapped it programmatically eventhough the Z Drive isn't showing in File Explorer.
How do I check whether the network drive is mapped by using c# or by using the command line?
My OS is Windows 10
I just powered off a mapped network drive in windows 7 and got false for Directory.Exists(). The linked question has about 10 different answers. This seems complex.
I would take a different approach.
try Directory.EnumerateDirectories("Z:\\") or some other mechanism for actually listing the contents of the drive and see if it throws an exception or fails to return anything (hopefully you could count on something being there). Even if there's 10 different ways a drive can be connected or not connected, for most of our purposes, if you can't access its contents, it's not connected.

Streaming large ipa files to iOS devices

Hey everyone I am working on a custom app store for iOS. However, I am having a problem when my system tries to stream large ipa files to the device. Sense there is no way to tell the device the total size of the file during the stream the status bar on the iOS device wont budge until the file is finished downloading then it almost completely fills the status bar in an instant and installs the file. This may leave users to think that the download isn't working at all. I am trying to find an alternative way to handle these large ipa files. I am currently thinking that I could allow the device to make a direct request to the file without hitting any .Net runtime code. I would probably be able to handle this through an ISAPI filter, but then I would need a way to authenticate that request to make sure the user has access to that download. Any advice or input would be appreciated.
Thanks.
You might consider pushing the apps into S3 and sending out signed CloudFront URLs to authenticated users:
http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls-overview.html
Alternatively, you could just give the .ipa files very obscure names that would be hard to guess.

Categories

Resources