2009-07-28 62 views
1

使用Process.StartProcessStartInfo模擬自動運行CD(或其他媒體,我猜)的最接近方式是什麼?從Process.Start自動運行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文件制定出涉及的可執行文件,但我只是想知道是否有一種簡單的方法來做到這一點。

回答

0

[檢查文件是否存在]

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 
+0

只是導致記事本打開文件的內容,對我來說。 – Thom 2009-07-30 09:26:25