Autorun A CD von Process.Start
-
19-09-2019 - |
Frage
Was ist der engste Weg, um Autorunning eine CD (oder andere Medien, denke ich) zu emulieren Process.Start
und ProcessStartInfo
?
Ich habe offensichtliche Dinge ausprobiert wie:
// 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"});
Ich kann das offensichtlich analysieren autorun.inf
Datei, um die ausführliche Datei zu erarbeiten, aber ich frage mich nur, ob es eine einfachere Möglichkeit gibt, dies zu tun.
Lösung
Überprüfen Sie, ob die Datei vorhanden ist
Process.Start(@"F:\autorun.inf");
Bearbeiten: Entschuldigung, Autorun scheint eine Explorer -Funktion zu sein. Sie müssen die Datei selbst analysieren.
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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow