C# 如何将cdrom驱动器号添加到来自cdrecord的行中

C# 如何将cdrom驱动器号添加到来自cdrecord的行中,c#,vb.net,C#,Vb.net,我是一个新手,正在为cmd行程序cdrecord开发windows窗体应用程序gui 我有一个组合框,在表单加载事件中,我将在组合框中显示cdrom驱动器 cdrecord使用此参数-scanbus I有两个驱动器,它们的显示方式如下: 'MATSHITA' 'DVD-R UJ-857E ' 'ZA0E' Removable CD-ROM 'HP ' 'DVD Writer 550r ' 'UH23' Removable CD-ROM 我也有代码来显示驱动器号 如何将驱动器号添加到cdreco

我是一个新手,正在为cmd行程序cdrecord开发windows窗体应用程序gui

我有一个组合框,在表单加载事件中,我将在组合框中显示cdrom驱动器

cdrecord使用此参数-scanbus I有两个驱动器,它们的显示方式如下:

'MATSHITA' 'DVD-R UJ-857E ' 'ZA0E' Removable CD-ROM
'HP ' 'DVD Writer 550r ' 'UH23' Removable CD-ROM
我也有代码来显示驱动器号

如何将驱动器号添加到cdrecord提供的名称的前面? 类似:D:\'MATSHITA''DVD-R UJ-857E'第一个驱动器 类似:F:\'HP''DVD Writer 550r''UH23'可移动CD-ROM

这是我的全部代码。任何帮助都将不胜感激。 谢谢


WMI应该具有来自硬件级别和操作系统级别的信息。照目前的情况,您似乎必须将收集的字符串与其他字符串进行匹配,以查看它们是如何映射的。为什么要添加c标记?你想要c答案吗?谢谢,我已经使用wmi来显示,它可以正常工作,但我试图找到一种不引用系统管理的方法,只使用cdrecord PRODUCTS的名称。如果您有驱动器号,并且确切知道它在阵列中的位置,那么只需追加。字符串final=@D:\+driveName;嗯,我想在不同的电脑上使用它。因此,在表单加载时,驱动器名称将不同。cdrecord-scanbus命令按顺序输出驱动器,驱动器盘符代码也是如此。所以我需要弄清楚如何将字母添加到相应的驱动器中。
        Imports System.IO
        Imports System.Text

        Public Class Form1
        Public Function FlattenWhitespace(ByVal pText As String) As String
        Dim strFlattened As String

        ' Convert non-space whitespace characters to spaces
        pText = Replace(pText, Chr(160), " ")
        pText = Replace(pText, vbTab, " ")
        pText = Replace(pText, vbCr, " ")
        pText = Replace(pText, vbLf, " ")

        ' Flatten multiple spaces in a row to a single space
        Do
            strFlattened = Replace(pText, "  ", " ")
            If Len(strFlattened) = Len(pText) Then
                ' The length of the string before & after the replacement is the same
                ' This means there is no more replacing to do (i.e. the string is as "flat" as it is going to get)
                Exit Do  ' Quit the loop
            End If
            pText = strFlattened
        Loop
        FlattenWhitespace = strFlattened
    End Function

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim p As New Process, pStartPath As String
        pStartPath = Application.StartupPath + "\tools\"
        p.StartInfo.FileName = pStartPath + "cdrecord.exe"
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.CreateNoWindow = True
        p.StartInfo.Arguments = " -scanbus"
        p.Start()

        'Takes all the standerd out and puts in a string
        Dim outStr As String = p.StandardOutput.ReadToEnd()

        'Splits the output and puts into lines
        Dim listOfLines As New List(Of String)(Split(outStr, Environment.NewLine))

        'Use stringbuilder to remove lines that don't contain CD-ROM
        Dim sb As New StringBuilder

        For Each LineOfText In listOfLines
            If LineOfText.Contains("CD-ROM") Then
                sb.AppendLine(LineOfText.Trim)
                outStr = sb.ToString
            End If
        Next

        'We have a new list now that just contains our cdrom drives
        Dim s As String() = Split(outStr, Environment.NewLine)

        For Each itm In s

            'Removes extra spaces and chars thats not needed to display nicely in the combobox
            itm = FlattenWhitespace(itm.Substring(itm.LastIndexOf(")"c) + 1))

            ' I have two cdrom drives and they both show on the msgbox
            ' I can't figure out why I'm getting a third msgbox that is empty
            MsgBox(itm)

            If Not String.IsNullOrEmpty(itm) Then
                'Adds itm to combobox1 and is displayed like:  'MATSHITA' 'DVD-R UJ-857E ' 'ZA0E' Removable CD-ROM
                ' And the second drive in displayed like:      'HP ' 'DVD Writer 550r ' 'UH23' Removable CD-ROM
                ComboBox1.Items.Add(itm)
                ComboBox1.SelectedIndex = 0
            End If
        Next

        'gets cdrom drive letter and put it in combobox2
        Dim drvLtr As String
        For Each drive In DriveInfo.GetDrives()

            If drive.DriveType = DriveType.CDRom Then
                drvLtr = drive.ToString
                'My first cdrom drive letter is displayed as D:\
                'And the second one is:                      F:\
                ComboBox2.Items.Add(drvLtr)
                ComboBox2.SelectedIndex = 0
            End If
        Next
    End Sub
End Class