Question

What is the closest way to emulate autorunning a CD (or other media, I guess) using Process.Start and ProcessStartInfo?

I've tried obvious things like:

// Just opens the folder
Process.Start("F:");

// Ditto
Process.Start(new ProcessStartInfo("F:") {UseShellExecute = true});

// Throws System.ComponentModel.Win32Exception: No application is associated with the specified file for this operation
Process.Start(new ProcessStartInfo("F:") {UseShellExecute = true, Verb = "autorun"});

I can obviously parse the autorun.inf file to work out the executable involved, but I'm just wondering if there's a simpler way to do it.

Was it helpful?

Solution

[Check if the file exists]

Process.Start(@"F:\autorun.inf");

EDIT: Sorry, autorun seems to be an Explorer feature. You will have to parse the file yourself.

Const DVD_DRIVE As String = "E:\"

If IO.File.Exists(DVD_DRIVE & "autorun.inf") Then
    Dim textreader As New IO.StreamReader(DVD_DRIVE & "autorun.inf")
    Dim sLine As String = ""

    sLine = textreader.ReadLine()
    Do While Not String.IsNullOrEmpty(sLine)
        If sLine.StartsWith("open=") Then
            Dim applicationstring As String
            Dim autorunapp As New Process()
            Dim startinfo As ProcessStartInfo

            applicationstring = sLine.Substring(5)

            startinfo = New ProcessStartInfo(DVD_DRIVE & applicationstring)

            startinfo.WorkingDirectory = DVD_DRIVE
            autorunapp.StartInfo = startinfo
            autorunapp.Start()

            Exit Do
        End If

        sLine = textreader.ReadLine()
    Loop

    textreader.Close()
End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top