最接近使用自动自动自动自动自动自动化CD(或其他媒体)的方法是什么 Process.StartProcessStartInfo?

我尝试了明显的事情:

// 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"});

我显然可以解析 autorun.inf 文件以确定所涉及的可执行文件,但我只是想知道是否有一种更简单的方法。

有帮助吗?

解决方案

检查文件是否存在

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

编辑:对不起,Autorun似乎是探索者功能。您将必须自己解析文件。

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top