determining drive types

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GregT

    #1

    determining drive types

    I program in C#. Is there a way to determine which of the local machine's
    logical drives are associated with CD drive(s)?
  • Bernie Yaeger

    #2
    Re: determining drive types

    Hi Greg,

    Try this:

    Dim drive As driveinfo
    Dim aldrives As New ArrayList

    drive = New driveinfo

    aldrives.Add(dr ive)

    The arraylist should not have the drive.descripti on of drive for each drive
    in your pc.

    HTH,

    Bernie Yaeger


    "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
    news:C34F67C5-E848-4AFB-AF5D-4D53F6D5AD1F@mi crosoft.com...[color=blue]
    >I program in C#. Is there a way to determine which of the local machine's
    > logical drives are associated with CD drive(s)?[/color]


    Comment

    • Bernie Yaeger

      #3
      Re: determining drive types

      Hi Again Greg,

      Oops - gave you vb .net code in my other reply - but you should be able to
      convert that easily.

      Bernie

      "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
      news:C34F67C5-E848-4AFB-AF5D-4D53F6D5AD1F@mi crosoft.com...[color=blue]
      >I program in C#. Is there a way to determine which of the local machine's
      > logical drives are associated with CD drive(s)?[/color]


      Comment

      • GregT

        #4
        Re: determining drive types

        Thanks Bernie,

        I'm trying to design code that will work on a user's machine when they run
        my program. I'm not sure I understand how this would help in that situation.
        I appreciate your feedback, am I missing something in interpreting what you
        wrote?

        "Bernie Yaeger" wrote:
        [color=blue]
        > Hi Again Greg,
        >
        > Oops - gave you vb .net code in my other reply - but you should be able to
        > convert that easily.
        >
        > Bernie
        >
        > "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
        > news:C34F67C5-E848-4AFB-AF5D-4D53F6D5AD1F@mi crosoft.com...[color=green]
        > >I program in C#. Is there a way to determine which of the local machine's
        > > logical drives are associated with CD drive(s)?[/color]
        >
        >
        >[/color]

        Comment

        • Bernie Yaeger

          #5
          Re: determining drive types

          Hi Greg,

          Here's the vb .net code again, but my explanation used 'not' when it should
          have said 'now':

          Dim drive As driveinfo
          Dim aldrives As New ArrayList

          drive = New driveinfo

          aldrives.Add(dr ive)

          The arraylist should NOW have the drive.descripti on of drive for each drive
          in your pc. The drive.descripti on will give you 'cd... etc'

          Bernie


          "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
          news:704DE320-197C-4CA0-8816-028695FACEA4@mi crosoft.com...[color=blue]
          > Thanks Bernie,
          >
          > I'm trying to design code that will work on a user's machine when they run
          > my program. I'm not sure I understand how this would help in that
          > situation.
          > I appreciate your feedback, am I missing something in interpreting what
          > you
          > wrote?
          >
          > "Bernie Yaeger" wrote:
          >[color=green]
          >> Hi Again Greg,
          >>
          >> Oops - gave you vb .net code in my other reply - but you should be able
          >> to
          >> convert that easily.
          >>
          >> Bernie
          >>
          >> "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
          >> news:C34F67C5-E848-4AFB-AF5D-4D53F6D5AD1F@mi crosoft.com...[color=darkred]
          >> >I program in C#. Is there a way to determine which of the local
          >> >machine's
          >> > logical drives are associated with CD drive(s)?[/color]
          >>
          >>
          >>[/color][/color]


          Comment

          • GregT

            #6
            Re: determining drive types

            Hi Bernie,

            Where is the drive info coming from that's being added to the array list?
            In other words how is "driveinfo" receiving the information? What is
            "driveinfo" ? I cannot find any references to it in the .NET help files. I'm
            sorry, but you lost me with "driveinfo" .

            "Bernie Yaeger" wrote:
            [color=blue]
            > Hi Greg,
            >
            > Here's the vb .net code again, but my explanation used 'not' when it should
            > have said 'now':
            >
            > Dim drive As driveinfo
            > Dim aldrives As New ArrayList
            >
            > drive = New driveinfo
            >
            > aldrives.Add(dr ive)
            >
            > The arraylist should NOW have the drive.descripti on of drive for each drive
            > in your pc. The drive.descripti on will give you 'cd... etc'
            >
            > Bernie
            >
            >
            > "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
            > news:704DE320-197C-4CA0-8816-028695FACEA4@mi crosoft.com...[color=green]
            > > Thanks Bernie,
            > >
            > > I'm trying to design code that will work on a user's machine when they run
            > > my program. I'm not sure I understand how this would help in that
            > > situation.
            > > I appreciate your feedback, am I missing something in interpreting what
            > > you
            > > wrote?
            > >
            > > "Bernie Yaeger" wrote:
            > >[color=darkred]
            > >> Hi Again Greg,
            > >>
            > >> Oops - gave you vb .net code in my other reply - but you should be able
            > >> to
            > >> convert that easily.
            > >>
            > >> Bernie
            > >>
            > >> "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
            > >> news:C34F67C5-E848-4AFB-AF5D-4D53F6D5AD1F@mi crosoft.com...
            > >> >I program in C#. Is there a way to determine which of the local
            > >> >machine's
            > >> > logical drives are associated with CD drive(s)?
            > >>
            > >>
            > >>[/color][/color]
            >
            >
            >[/color]

            Comment

            • Bernie Yaeger

              #7
              Re: determining drive types

              Hi Greg,

              I'm sorry for confusing you; I've not given you all the code, but once I
              explain, I think this will help you.

              I am currently reading 'developing .net controls with vb .net'. One of the
              chapters deals with placing icons and names of drives in a selection
              combobox - I've changed it to a listbox, but it works fine. One of the
              things it does, is query the pc for all of its drives and then assigns
              descriptions and icons that match - cd rom drive, c drive, a floppy, etc.
              This is exactly the kind of info I believe you could use. So create a form
              called 'aownerdraw', add a listbox called 'cbdrives', set its drawmode to
              'ownerdrawfixed ' and use this complete code (driveinfo is a class that is
              created at the bottom of this code sample). This should give you the info
              you need to roll your own code to meet your needs.

              Imports System.Collecti ons

              Public Class aownerdraw

              Inherits System.Windows. Forms.Form

              Dim drive As driveinfo

              Dim aldrives As New ArrayList

              Dim mgtobjectsearch er As System.Manageme nt.ManagementOb jectSearcher

              Dim mgtobject As System.Manageme nt.ManagementOb ject

              +windows form designer generated code goes here

              Private Sub aownerdraw_Load (ByVal sender As System.Object, ByVal e As
              System.EventArg s) Handles MyBase.Load

              mgtobjectsearch er = New System.Manageme nt.ManagementOb jectSearcher("s elect *
              from win32_logicaldi sk")

              drive = New driveinfo

              With drive

              ..drivedescript ion = "Desktop"

              ..driveletter = "Desktop"

              ..driveletter = 0

              End With

              aldrives.Add(dr ive)

              Call updatedrives()

              Call adddrivestocomb o()

              End Sub

              Private Sub updatedrives()

              For Each mgtobject In mgtobjectsearch er.Get()

              drive = New driveinfo

              Dim sdrivedescripti on As String = ""

              sdrivedescripti on = mgtobject.Prope rties("DeviceID ").Value

              drive.drivelett er = sdrivedescripti on

              sdrivedescripti on &= "\ " & mgtobject.Prope rties("Descript ion").Value

              If IsNothing(mgtob ject.Properties ("Size").Val ue) Then

              sdrivedescripti on &= " Not Available"

              Else

              sdrivedescripti on &= " " & mgtobject.Prope rties("VolumeNa me").Value

              End If

              drive.drivedesc ription = sdrivedescripti on

              Select Case Convert.ToInt16 (mgtobject.Prop erties("DriveTy pe").Value)

              Case 0 : drive.driveimag e = 6

              Case 1 : drive.driveimag e = 6

              Case 2 : drive.driveimag e = 1

              Case 3 : drive.driveimag e = 2

              Case 4 : drive.driveimag e = 4

              Case 5 : drive.driveimag e = 3

              Case 6 : drive.driveimag e = 0

              End Select

              If (drive.driveima ge = 4) Then

              If sdrivedescripti on.IndexOfAny(" Not Available") > 0 Then

              drive.driveimag e = 5

              End If

              End If

              aldrives.Add(dr ive)

              Next

              End Sub

              Private Sub adddrivestocomb o()

              Dim ddrive As driveinfo

              Dim i As Integer

              For Each ddrive In aldrives

              cbdrives.Items. Add("")

              Next

              If aldrives.Count > 0 Then

              cbdrives.Select edIndex = 0

              End If

              End Sub

              Private Sub cbdrives_DrawIt em(ByVal sender As System.Object, ByVal e As
              System.Windows. Forms.DrawItemE ventArgs) Handles cbdrives.DrawIt em

              e.DrawBackgroun d()

              e.DrawFocusRect angle()

              If e.Index = 0 Then

              Exit Sub

              End If

              Dim ioffset As Integer = 0

              If e.Index < 0 Then

              ioffset = 0

              Else

              ioffset = 10

              End If

              Dim ddrive As New driveinfo

              ddrive = aldrives(e.Inde x)

              Dim sdrivedescripti on As String = ddrive.drivedes cription

              Dim idriveimage As Integer = ddrive.driveima ge

              Dim bmdrivebmp As Bitmap = ildrives.Images (idriveimage)

              Dim abrush As Brush = System.Drawing. Brushes.Black

              Dim sformat As StringFormat = StringFormat.Ge nericTypographi c

              Dim itemheight As Integer = cbdrives.ItemHe ight

              e.DrawBackgroun d()

              e.DrawFocusRect angle()

              e.Graphics.Draw Image(bmdrivebm p, ioffset, e.Bounds.Top + (itemheight -
              bmdrivebmp.Heig ht) \ 2)

              If (e.State And DrawItemState.S elected) Then

              abrush = System.Drawing. Brushes.White

              End If

              sformat.LineAli gnment = StringAlignment .Center

              e.Graphics.Draw String(sdrivede scription, e.Font, abrush, (20 + ioffset),
              e.Bounds.Top + (e.Bounds.Heigh t \ 2), sformat)

              End Sub

              End Class

              Friend Class driveinfo

              Dim m_driveletter As String = ""

              Dim m_drivedescript ion As String

              Dim m_driveimage As Integer = 0

              Sub New()

              End Sub

              Friend Property driveletter() As String

              Get

              Return m_driveletter

              End Get

              Set(ByVal Value As String)

              m_driveletter = Value

              End Set

              End Property

              Friend Property drivedescriptio n() As String

              Get

              Return m_drivedescript ion

              End Get

              Set(ByVal Value As String)

              m_drivedescript ion = Value

              End Set

              End Property

              Friend Property driveimage() As Integer

              Get

              Return m_driveimage

              End Get

              Set(ByVal Value As Integer)

              m_driveimage = Value

              End Set

              End Property

              End Class

              HTH,

              Bernie



              "Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
              news:ehHKFVCJFH A.2704@tk2msftn gp13.phx.gbl...[color=blue]
              > Hi Greg,
              >
              > Here's the vb .net code again, but my explanation used 'not' when it
              > should have said 'now':
              >
              > Dim drive As driveinfo
              > Dim aldrives As New ArrayList
              >
              > drive = New driveinfo
              >
              > aldrives.Add(dr ive)
              >
              > The arraylist should NOW have the drive.descripti on of drive for each
              > drive
              > in your pc. The drive.descripti on will give you 'cd... etc'
              >
              > Bernie
              >
              >
              > "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
              > news:704DE320-197C-4CA0-8816-028695FACEA4@mi crosoft.com...[color=green]
              >> Thanks Bernie,
              >>
              >> I'm trying to design code that will work on a user's machine when they
              >> run
              >> my program. I'm not sure I understand how this would help in that
              >> situation.
              >> I appreciate your feedback, am I missing something in interpreting what
              >> you
              >> wrote?
              >>
              >> "Bernie Yaeger" wrote:
              >>[color=darkred]
              >>> Hi Again Greg,
              >>>
              >>> Oops - gave you vb .net code in my other reply - but you should be able
              >>> to
              >>> convert that easily.
              >>>
              >>> Bernie
              >>>
              >>> "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
              >>> news:C34F67C5-E848-4AFB-AF5D-4D53F6D5AD1F@mi crosoft.com...
              >>> >I program in C#. Is there a way to determine which of the local
              >>> >machine's
              >>> > logical drives are associated with CD drive(s)?
              >>>
              >>>
              >>>[/color][/color]
              >
              >[/color]


              Comment

              • GregT

                #8
                Re: determining drive types

                Thanks Bernie,

                it's much clearer now.

                "Bernie Yaeger" wrote:
                [color=blue]
                > Hi Greg,
                >
                > I'm sorry for confusing you; I've not given you all the code, but once I
                > explain, I think this will help you.
                >
                > I am currently reading 'developing .net controls with vb .net'. One of the
                > chapters deals with placing icons and names of drives in a selection
                > combobox - I've changed it to a listbox, but it works fine. One of the
                > things it does, is query the pc for all of its drives and then assigns
                > descriptions and icons that match - cd rom drive, c drive, a floppy, etc.
                > This is exactly the kind of info I believe you could use. So create a form
                > called 'aownerdraw', add a listbox called 'cbdrives', set its drawmode to
                > 'ownerdrawfixed ' and use this complete code (driveinfo is a class that is
                > created at the bottom of this code sample). This should give you the info
                > you need to roll your own code to meet your needs.
                >
                > Imports System.Collecti ons
                >
                > Public Class aownerdraw
                >
                > Inherits System.Windows. Forms.Form
                >
                > Dim drive As driveinfo
                >
                > Dim aldrives As New ArrayList
                >
                > Dim mgtobjectsearch er As System.Manageme nt.ManagementOb jectSearcher
                >
                > Dim mgtobject As System.Manageme nt.ManagementOb ject
                >
                > +windows form designer generated code goes here
                >
                > Private Sub aownerdraw_Load (ByVal sender As System.Object, ByVal e As
                > System.EventArg s) Handles MyBase.Load
                >
                > mgtobjectsearch er = New System.Manageme nt.ManagementOb jectSearcher("s elect *
                > from win32_logicaldi sk")
                >
                > drive = New driveinfo
                >
                > With drive
                >
                > ..drivedescript ion = "Desktop"
                >
                > ..driveletter = "Desktop"
                >
                > ..driveletter = 0
                >
                > End With
                >
                > aldrives.Add(dr ive)
                >
                > Call updatedrives()
                >
                > Call adddrivestocomb o()
                >
                > End Sub
                >
                > Private Sub updatedrives()
                >
                > For Each mgtobject In mgtobjectsearch er.Get()
                >
                > drive = New driveinfo
                >
                > Dim sdrivedescripti on As String = ""
                >
                > sdrivedescripti on = mgtobject.Prope rties("DeviceID ").Value
                >
                > drive.drivelett er = sdrivedescripti on
                >
                > sdrivedescripti on &= "\ " & mgtobject.Prope rties("Descript ion").Value
                >
                > If IsNothing(mgtob ject.Properties ("Size").Val ue) Then
                >
                > sdrivedescripti on &= " Not Available"
                >
                > Else
                >
                > sdrivedescripti on &= " " & mgtobject.Prope rties("VolumeNa me").Value
                >
                > End If
                >
                > drive.drivedesc ription = sdrivedescripti on
                >
                > Select Case Convert.ToInt16 (mgtobject.Prop erties("DriveTy pe").Value)
                >
                > Case 0 : drive.driveimag e = 6
                >
                > Case 1 : drive.driveimag e = 6
                >
                > Case 2 : drive.driveimag e = 1
                >
                > Case 3 : drive.driveimag e = 2
                >
                > Case 4 : drive.driveimag e = 4
                >
                > Case 5 : drive.driveimag e = 3
                >
                > Case 6 : drive.driveimag e = 0
                >
                > End Select
                >
                > If (drive.driveima ge = 4) Then
                >
                > If sdrivedescripti on.IndexOfAny(" Not Available") > 0 Then
                >
                > drive.driveimag e = 5
                >
                > End If
                >
                > End If
                >
                > aldrives.Add(dr ive)
                >
                > Next
                >
                > End Sub
                >
                > Private Sub adddrivestocomb o()
                >
                > Dim ddrive As driveinfo
                >
                > Dim i As Integer
                >
                > For Each ddrive In aldrives
                >
                > cbdrives.Items. Add("")
                >
                > Next
                >
                > If aldrives.Count > 0 Then
                >
                > cbdrives.Select edIndex = 0
                >
                > End If
                >
                > End Sub
                >
                > Private Sub cbdrives_DrawIt em(ByVal sender As System.Object, ByVal e As
                > System.Windows. Forms.DrawItemE ventArgs) Handles cbdrives.DrawIt em
                >
                > e.DrawBackgroun d()
                >
                > e.DrawFocusRect angle()
                >
                > If e.Index = 0 Then
                >
                > Exit Sub
                >
                > End If
                >
                > Dim ioffset As Integer = 0
                >
                > If e.Index < 0 Then
                >
                > ioffset = 0
                >
                > Else
                >
                > ioffset = 10
                >
                > End If
                >
                > Dim ddrive As New driveinfo
                >
                > ddrive = aldrives(e.Inde x)
                >
                > Dim sdrivedescripti on As String = ddrive.drivedes cription
                >
                > Dim idriveimage As Integer = ddrive.driveima ge
                >
                > Dim bmdrivebmp As Bitmap = ildrives.Images (idriveimage)
                >
                > Dim abrush As Brush = System.Drawing. Brushes.Black
                >
                > Dim sformat As StringFormat = StringFormat.Ge nericTypographi c
                >
                > Dim itemheight As Integer = cbdrives.ItemHe ight
                >
                > e.DrawBackgroun d()
                >
                > e.DrawFocusRect angle()
                >
                > e.Graphics.Draw Image(bmdrivebm p, ioffset, e.Bounds.Top + (itemheight -
                > bmdrivebmp.Heig ht) \ 2)
                >
                > If (e.State And DrawItemState.S elected) Then
                >
                > abrush = System.Drawing. Brushes.White
                >
                > End If
                >
                > sformat.LineAli gnment = StringAlignment .Center
                >
                > e.Graphics.Draw String(sdrivede scription, e.Font, abrush, (20 + ioffset),
                > e.Bounds.Top + (e.Bounds.Heigh t \ 2), sformat)
                >
                > End Sub
                >
                > End Class
                >
                > Friend Class driveinfo
                >
                > Dim m_driveletter As String = ""
                >
                > Dim m_drivedescript ion As String
                >
                > Dim m_driveimage As Integer = 0
                >
                > Sub New()
                >
                > End Sub
                >
                > Friend Property driveletter() As String
                >
                > Get
                >
                > Return m_driveletter
                >
                > End Get
                >
                > Set(ByVal Value As String)
                >
                > m_driveletter = Value
                >
                > End Set
                >
                > End Property
                >
                > Friend Property drivedescriptio n() As String
                >
                > Get
                >
                > Return m_drivedescript ion
                >
                > End Get
                >
                > Set(ByVal Value As String)
                >
                > m_drivedescript ion = Value
                >
                > End Set
                >
                > End Property
                >
                > Friend Property driveimage() As Integer
                >
                > Get
                >
                > Return m_driveimage
                >
                > End Get
                >
                > Set(ByVal Value As Integer)
                >
                > m_driveimage = Value
                >
                > End Set
                >
                > End Property
                >
                > End Class
                >
                > HTH,
                >
                > Bernie
                >
                >
                >
                > "Bernie Yaeger" <berniey@cherwe llinc.com> wrote in message
                > news:ehHKFVCJFH A.2704@tk2msftn gp13.phx.gbl...[color=green]
                > > Hi Greg,
                > >
                > > Here's the vb .net code again, but my explanation used 'not' when it
                > > should have said 'now':
                > >
                > > Dim drive As driveinfo
                > > Dim aldrives As New ArrayList
                > >
                > > drive = New driveinfo
                > >
                > > aldrives.Add(dr ive)
                > >
                > > The arraylist should NOW have the drive.descripti on of drive for each
                > > drive
                > > in your pc. The drive.descripti on will give you 'cd... etc'
                > >
                > > Bernie
                > >
                > >
                > > "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
                > > news:704DE320-197C-4CA0-8816-028695FACEA4@mi crosoft.com...[color=darkred]
                > >> Thanks Bernie,
                > >>
                > >> I'm trying to design code that will work on a user's machine when they
                > >> run
                > >> my program. I'm not sure I understand how this would help in that
                > >> situation.
                > >> I appreciate your feedback, am I missing something in interpreting what
                > >> you
                > >> wrote?
                > >>
                > >> "Bernie Yaeger" wrote:
                > >>
                > >>> Hi Again Greg,
                > >>>
                > >>> Oops - gave you vb .net code in my other reply - but you should be able
                > >>> to
                > >>> convert that easily.
                > >>>
                > >>> Bernie
                > >>>
                > >>> "GregT" <GregT@discussi ons.microsoft.c om> wrote in message
                > >>> news:C34F67C5-E848-4AFB-AF5D-4D53F6D5AD1F@mi crosoft.com...
                > >>> >I program in C#. Is there a way to determine which of the local
                > >>> >machine's
                > >>> > logical drives are associated with CD drive(s)?
                > >>>
                > >>>
                > >>>[/color]
                > >
                > >[/color]
                >
                >
                >[/color]

                Comment

                Working...