【问题标题】:Autorun a CD from Process.Start从 Process.Start 自动运行 CD
【发布时间】:2009-07-28 12:33:21
【问题描述】:

使用Process.StartProcessStartInfo 模拟自动运行CD(或其他媒体,我猜)的最接近的方法是什么?

我已经尝试过明显的事情,例如:

// 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 文件以计算出所涉及的可执行文件,但我只是想知道是否有更简单的方法。

【问题讨论】:

    标签: .net windows system.diagnostics autorun


    【解决方案1】:

    [检查文件是否存在]

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

    编辑:抱歉,自动运行似乎是资源管理器的一项功能。您必须自己解析文件。

    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
    

    【讨论】:

    • 对我来说,只会导致记事本打开文件内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 2013-04-30
    • 2013-09-11
    • 1970-01-01
    • 2012-07-01
    • 2015-10-17
    • 1970-01-01
    相关资源
    最近更新 更多