2009-07-28 8 views
1

Quelle est la manière la plus proche d'émuler automatiquement un CD (ou un autre média, je suppose) en utilisant Process.Start et ProcessStartInfo?Autorun un CD de Process.Start

J'ai essayé des choses évidentes comme:

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

je peux analyser évidemment le fichier autorun.inf pour travailler sur l'exécutable impliqué, mais je me demande s'il y a un moyen plus simple de le faire.

Répondre

0

[Vérifiez si le fichier existe]

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

EDIT: Désolé, autorun semble être une caractéristique de l'Explorateur. Vous devrez analyser le fichier vous-même.

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

Juste les résultats dans l'ouverture du bloc-notes avec le contenu du fichier, pour moi. – Thom

Questions connexes