从 Process.Start 自动运行 CD

发布于 2024-07-30 06:53:30 字数 522 浏览 8 评论 0原文

使用 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 文件来计算出涉及的可执行文件,但我只是想知道是否有更简单的方法来做到这一点。

What is the closest way to emulate autorunning a CD (or other media, I guess) using Process.Start and ProcessStartInfo?

I've tried obvious things like:

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

I can obviously parse the autorun.inf file to work out the executable involved, but I'm just wondering if there's a simpler way to do it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

或十年 2024-08-06 06:53:30

[检查文件是否存在]

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

[Check if the file exists]

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

EDIT: Sorry, autorun seems to be an Explorer feature. You will have to parse the file yourself.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文