Reading USB flash disk issue - c#

I am using Visual Studio Team System 2008, C#, .NET 3.5, IIS 7.0, and ASP.NET. I am using Silverlight 3.0 as well. I want to read the content of a USB flash disk at the client side, using the information in the USB flash disk as a user profile identifier -- just like an online bank service is using a USB key to store a client certificate (but my security requirement is not that high).
How the content of a specific file in a USB flash disk in a web application (at the client side) be read? Could we do this in Silverlight (if can not, any alternative solution to read USB flash disk content)?
BTW: I want to read the content automatically, and I do not want the user to manually select the specific file on the USB flash disk to read.

You can not do this in Silverlight. You can read a file on the user's machine, but not without user intervention. The security model built into Silverlight will not allow it.
The best you can do is to read a user-specified file is to have them browse to it with a
file-open dialog box.
You can access the USB/flash drive if you are using a console/Windows Forms/WPF application locally. You can find the drives using the DriveInfo class, then iterate over them or use a LINQ query to find the drive you want to access. See the Stack Overflow question "How to find USB drive letter?" for details. Once you have a path, you can search it for the file you want. You do not need a special API or library, the Windows OS treats the USB drive as a normal drive, same as a "permanent" HDD connected to your system, and will do all the dirty work for you at that level. Just use the .NET I/O classes. However, if you wish to access the drive in an independent manner that does not depend on any OS, then you should use a 3rd party library.

I don't think what you're asking for is possible. If it IS possible, that's scary stuff... To allow a web site to grab stuff without user intervention? Uh-Uh. No way.\
Edit - Added after reading the comment
Using only the standard framework, no. USB support is not something that comes standard. You'd think there would be some classes in the System.IO namespace for USB ports like there are for COM ports, but no such luck. However, there are some libraries that will handle this. Here are some links to get you started.
http://weblogs.asp.net/israelio/archive/2005/08/15/422637.aspx
http://www.icsharpcode.net/OpenSource/SharpUSBLib/

Related

Trying to get Hard Drive Serial Number into a SQL Server via UWP app

I'm a relatively new Developer building my first app.
Right now I'm in the process of developing a UWP app and I am needing to get the Hard Drive Serial number from the PC from the Views (OnNavigatedTo), then after a few more fields are filled out, to then save all values to a SQL Server.
What I have discovered up to this point:
Grabbing some values like Hard Drive SN are not so easy with UWP.
I don't seem to have access to Registry HKLM via UWP
I can grab it very easily with PowerShell, and write it to a JSON or XML file. which I plan to do with a Service Account when PC is imaged.
I Don't know where to put the file where the App can see it.
Writing to Sql Server can only be done by creating a webservice and making HTTP / JSON calls via App. (I have this part setup but have not started accessing it via app yet)
So the part I really need help with I guess, is Where to Put JSON/XML file that App will be able to see and read from. Unless of course, someone knows of another way to get Hard Drive SN into a UWP app.
Thanks for Any Help
The recommended way to do this (if you want to go to the Windows Store) is to use a FileOpenPicker and have the user choose the file manually.
If this is for side-loading only (not going to the Windows Store) you can write the file to the user's Documents folder and then the UWP can read it using documentsLibrary capability without any user intervention. You could also use a fullTrust extension to run the PowerShell script and to put the file in the app's data folder. You can check out the Desktop Bridge docs for more info on fullTrust extensions.

How can I access a client side dll from a server side application?

In my current project we are trying to integrate a card reader into a
website. The problem is that we have to have the Windows Service
sitting on the clients machine in order for the card reader to work.
The purpose of the website is to have the client scan the card through
the card reader and have the information be sent to the database
through a web service. After the information is saved to the database
it can then be retrieved and shown on the site.
The question I have is
how can I access a .dll, that I have written, from the the asp page
sitting on the server. I know that I could use ActiveX but I am trying to
access the .dll in a way that will allow me to have the webpage be used in
as many browsers as possible.
I am thinking of using silverlight to try and access the dll. The .dll in
question is one that I have written and am trying to access. I've also looked
at trying the DLLImport but I've not been able to get it to work. I am currently using
.NET 4.0 and am writing in C#.
If your client is reading a smartcard, it might be a good idea to use the built-in windows features to use a smartcard to authenticate to IIS on the remote computer. If you're trying to read anything else from the smartcards, then it's usually better to offer the client a normal installer that registers itself as a security device, Browsers have built-in functionality to communicate to such a device. Our local bank, ABN AMRO, uses such a device which is sold by Todos AB and which comes with a driver that works in this fashion.
If you want to do anything else with the smartcard (anything other than reading a certificate or a security token, you'll probably have no other option than to offer the user with a download that I'd personally would always deny.

Simulate a network share in order to share files

Often times a program requires a file that happens to be on a network location. Take for instance Outlook. If I where to place an outlooks database (.pst file) in a network location then windows will make that "transparent" to the user and outlook will still be able to work. Another example could be quickbooks and many more. (as long as you have permissions to write and read)
For this example let's use Microsoft Word. If I would want to open a file in some other computer in the network I would be able to navigate to it as:
and open the file that I want because we are on the same network.
Now my question is how will I be able to simulate that? I want to have a virtual directory on the internet where I can place lets say my .pst file and then select it from windows explorer as:
(this example obviously does not work)
Will it be possible to do that? I believe windows uses a tcp connection with the host computer and then the host responds with he files that it shares. I will like to implement a program that does that so that I could avoid having to create a vpn. Also it will be nice if I could have my pst (outlook database file) on the internet so that all my computers open the same outlook database.
Note my purpose of this question is to open an outlook database file on a network location. I will like to be able to select a file on the internet from windows open file dialog. Also in todays world everything pretty much exists. I will like to create it lol
Windows provides a network redirector for CIFS (Common Internet File System, formerly SMB Server Message Block) resources. Writing a CIFS server is the easiest approach.
But you can also use one of the other existing redirectors, such as NFS, WebDAV, or Netware. And it's also possible to write new redirectors (though that requires kernel mode code, there are some development kits that provide the kernel code for you, similar to a Linux FUSE filesystem).
If you want to avoid writing code, WebDAV over HTTPS will provide you secure access (no need for a VPN layer) and software already exists.
It depends on how the server on the internet is set up to make its files available. Most often tcpip is not the protocol used for this - it is FTP, SFTP, HTTP or something similar. I believe Windows Explorer uses RPC calls over a local network to accomplish this. I don't think you will be able to use the Open File Dialog, you will have to write something similar that works over the protocol you need to use.

Windows virtual disk for remote web service

I need to implement a Windows Virtual Disk that is visible as a separate disk device in Windows Explorer and transfer all files/dir transferred forth and back to a remote WebService - sth like a DropBox.
Do I have to implement/use a kernel driver SDK? Or is it possoible to use only shell extensions? What I need is to intercept all file/dir operations on that disk and map them to a corresponding WebService calls (file creation/deletion/move/edit and data transfer).
Thanks
You will need a combination of kernel-mode driver and Windows Service/Application for that:
http://dokan-dev.net/en/ (free)
http://www.eldos.com/cbfs/ (commercial)
Windows 7+ allows you to mount a VHD as a disk. The API is described in this MSDN article -The Virtual Disk API In Windows 7.
I don't know if it's possible with just shell extensions, but scanning the article I see the API AttachVirtualDisk, and you should be able to P/Invoke that.
Have you considered WebDAV? This wouldn't require you to install anything on the client, since the functionality is integrated into Windows (I believe since XP). It is using REST, so you could even implement it yourself or look for a solution on codeplex. If it is just about remote storage, there is an IIS addon you can use for that (I believe it is build for IIS 7).
You can go with namespace extensions, this is what DropBox does. Wuala and some other cloud storage provides, on the other hand, use our Callback File System to create a virtual disk.

Connect and disconnect USB programmaticaly "WITHOUT UNPLUG AND REPLUG"

I need to connect and disconnect USB programmatically. That is, I have inserted the USB device. I need to transfer the file using C#, .NET application. The application will watch the particular folder and transfer the file from that folder to a USB drive. I need to disconnect the USB device after the file is transfered and connect the USB when needed - without unplug and replug.
What would be some code to do it or is there any DLL file available?
Main thing: NOTE, NOTE: Without unplugging and replugging the USB device.
If your goal is to make a certain disk volume unavailable while you're not using it, a more sensible approach might be to use the volume management APIs, e.g. by using the IOCTL_VOLUME_OFFLINE control code. (I'm assuming that you know which drive letter belongs to your USB disk.)
Alternatively, you can disable and enable the volume device programmatically with the CfgMgr / SetupAPI -- the same as right-clicking the volume in Device Manager and choosing Disable would do. (For information about using SetupAPI, please review the DevCon sample code provided with the Windows WDK, and see MSDN for functions such as SetupDiChangeState.)
The latter option might require a privileged user account.
I'm not exactly sure, but it can be done. In Linux, I've experienced certain situations where power is disconnected to a device programmatically. The kernel usually does this if the connected USB device is exhibiting too many errors. So, it should be possible to do this even in Windows. You may need to write your own external DLL to do it though.

Categories