Autorun when USB stick is inserted - usb

I'm trying to prompt users to run my installer, whenever they plug in my USB device. I'd like this to work on all (most?) Windows OSes.
I have an autorun.inf file in the root dir of my USB key with these contents:
[Autorun]
ShellExecute=setup.exe
Icon=setup.exe
UseAutoplay=1
It doesn't seem to do very much at all. Well... it does change the icon properly, but nothing gets executed and the user doesn't get any prompts. I've tried it on both Windows 7 and Windows Server 2003.
Any ideas?

USB mass storage devices do not perform Autorun on Windows. You need to enumerate as a USB CD-ROM device in order to support autorun.
If you have a U3 capable USB drive, you can often replace the U3 data with your own CD image.
If this is a custom USB device, you will need to implement a composite device with the Mass Storage and USB CD-ROM device (or just the CD-ROM if you don't want to supporting writing).

Related

Make USB appear as a CD

Right. So I've been looking at VBS Scripts and batch files recently and autorun.inf would really be the cherry on the cake (don't worry I don't plan on using it as a tool for evil). I know that it has been turned off by default on Windows 7 onward but I read somewhere that it is still on for CDs. So naturally, I wonder - Is it possible to make the USB drive look as if it were a CD to make autorun work?
a USB pen drive and a USB CD tray have the same device class (USB mass storage device class). the problem is that despite the same device class there are other parts in USB protocol that differ (interface descriptors, configuration descriptors, endpoint descriptors,...) These usb descriptors that are also responsible for what driver / kernel module is loaded by the os, are hardcoded in the firmware of the device. your only chance to make a pen drive appear as a CD is to change these hardcoded descriptors or what is easier, to build your own device using a microcontroller with USB functionality in that you program your custom descriptors. Note that kernel modules and drivers are based on standardized protocol so your descriptors have fit these standards for the device to work.
In http://www.beyondlogic.org/usbnutshell/usb1.shtml is more information about USB protocol and the descriptors...

on windows 7/8, how to read usb device descriptor from a usb camera, and read picture stream with webcam meanwhile

I use webcam-capture(java api) to get video stream from a usb camera, it work fine.
I want read a usb device descriptor(store some private information), i find out that should install WinUSB or libusbk as a driver to the usb devices. and it test ok, read the descriptor success (by libusb_control_transfer api)
the question is:
befor I install WinUSB, the usb camera is a camera device in the windows device management list. the LibUSB work fail, can't open the usb devices, the error number is -5, means entrypoin not find
after I install WinUSB, libUSB api work ok, but the webcam program can't open the usb devices, it is a universal usb device in the windows device management list.
is there some way the webcam work ok, at the same time, i can read the usb device descriptor use libusb or use other something?
i tested on windows 7 and windows 8, have the same problem.
thanks.
Sadly this is not possible because each of your applications needs a different driver. The only way this can work is if you use libusb and build you own capturing api on top which is quite complicated. As long as webcam-capture can not read the data you want to know about the webcam I am afraid this is not possible.

Trouble with Win 10 writing files to a USB device

I have a USB device with flash memory that looks like a USB FAT16 flash drive to a PC. The device stores VB.net product support software files.
As part of the flash update process the device firmware re-formats flash memory and sets the media change state. Win XP thru Win 8.1 refresh the devices file system and the device shows as an empty drive. From there we copy. Works great.
Windows 10 (since the anniversary update) doesn't pay attention to the media change state. After the device re-formats the flash Win 10 still shows all the files that have been erased. Copying files at this point fails. The only way to recover is to unplug, then plug in the USB connector.
I have tried using DeviceIoControl(IOCTL_INTERNAL_USB_CYCLE_PORT) from my application. This only sometimes works.
Is there a better way to programmatically force Win 10 to refresh its view of the USB flash in the device without unplugging it?

How to use usb flash or virtual drive to act as a plug and play device?

I am trying to find a way to mimic a USB device being connected without actually having it available. I am trying to develop an additional feature to software that is only fully unlocked when the USB device is connected to the computer. Because the client is unable to provide a demo device for me to use here shortly, I'd like to find a way to emulate or mimic the connectivity of the device so I can finish development. Can I do this with a flash drive perhaps? Find someway to copy the files so that when I insert the flash drive it acts as a plug and play device?

How to emulate USB devices?

The rest of my team will make for my application a simple non-standard USB microphone, but until they finish it I will have to emulate it, for integration testing purposes.
Is there any risk in a physical loopback? Yes there is
Will a physical loopback work? Only with a USB bridge
There is any way to create a logical loopback? (MSDN has something about this)
There is any general purpose USB emulator software?
In case there is many options available I'd rather work it .NET/Matlab/Python solutions.
Edit: Proof of concept here
I strongly recommend this project, USB IP. It is a way of connecting USB devices over the network. There is a Windows client.
What this means is, you install the client on your Windows computer.
This device then expects to talk to a USB device connected to a Linux computer, the server:
What you now do, is either create a fake device driver for Linux, that looks like is connected to a physical USB device, but in reality is just logic pretending to be your USB device. There are tutorials for writing USB drivers for Linux. Or you create your own stub driver for the Device Control Manager (see picture above). This stub driver could run on Windows or Linux, it wouldn't matter. It could even run on the same Windows machine which is the USB client.
The DSF USB Loopback Device mentioned in the question itself, would be the same kind of solution as a stub driver for the Device Control Manager, but taking Linux out of the picture altogether.
You can write virtual USB device using QEMU.
You can duplicate already existing device, like the dev-serial.c found in this QEMU repository and change it for your needs.
After you write and compile your USB device you can simply attach it to your VM using the QEMU command line interface.