c# create media at runtime

434 Views Asked by At

I want to add a backup functionality to my app in the sense that the app will allow users to create a self-contained environment (data + executable + autorun.inf file) on an external device (CD, CD-ROM or USB key) so that users can retrieve (in read only mode) their stored environment at a given point in time.

I've read here about making an auto-bootable USB (which I suspect will be the same for a CD or DVD).

edit I meant "auto-executing", not "auto-bootable"!

I know about IMAPI or other approaches that are now several years old. Is there any alternative/standard approach to create media this way? I'd like a generic way to create either CD/DVD or USB devices (non-bootable).

1

There are 1 best solutions below

2
On BEST ANSWER

You need to make sure to not confuse Booting and Windows Autorun.

auto-bootable USB

refers to an external USB drive from which you can boot your computer. I doubt that's what you are looking for, given the linked Stackexchange question. The information you already found is actually what you are looking for, and the advice given there seems pretty accurate.

What you need to do is:

  1. Create the media with your data. In case of USB sticks this is as easy as copying the data to the stick. Optical media (CD/DVD) need to be burned, and that can only be done using the Windows API, which has already be discussed here.
  2. If you want to use the Windows autorun feature (which I would ignore*), you'll need to create a file called Autorun.ini in the root directory of your media. You already have found the required content of that file here.

* Why I would skip the autorun feature.

First of all, there's no real alternative to the Windows autorun feature. It was controversial, at best, in earlier versions of Windows. Since USB sticks went mainstream, autorun became nothing more than an automatic virus installation feature. Soon after everyone started disabling it. Because of this recent versions of Windows seem to have dropped it or disable it by default.

An exception to this would be the Icon=diskicon.ico option, which allows you to change the icon of the drive. This might be still working, even if autorun is disabled.