Autorun un CD de Process.starter
-
19-09-2019 - |
Question
Quelle est la façon la plus proche d'imiter la mise en œuvre d'un CD (ou d'autres médias, je suppose) en utilisant Process.Start
et ProcessStartInfo
?
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 évidemment analyser le autorun.inf
Déposer pour déterminer l'exécutable impliqué, mais je me demande simplement s'il existe un moyen plus simple de le faire.
La solution
Vérifiez si le fichier existe
Process.Start(@"F:\autorun.inf");
Edit: Désolé, Autorun semble être une fonctionnalité d'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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow