使用Process.Start
和ProcessStartInfo
模拟自动播放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 :(得分: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