代码之家  ›  专栏  ›  技术社区  ›  Thom

从进程自动运行CD。启动

  •  1
  • Thom  · 技术社区  · 15 年前

    模拟自动运行CD(或其他媒体,我猜)的最接近方法是 Process.Start ProcessStartInfo ?

    我尝试过一些显而易见的事情,比如:

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

    1 回复  |  直到 15 年前
        1
  •  0
  •   ZippyV    15 年前

    [检查文件是否存在]

    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