PC Review


Reply
Thread Tools Rate Thread

determining drive types

 
 
=?Utf-8?B?R3JlZ1Q=?=
Guest
Posts: n/a
 
      8th Mar 2005
I program in C#. Is there a way to determine which of the local machine's
logical drives are associated with CD drive(s)?
 
Reply With Quote
 
 
 
 
Bernie Yaeger
Guest
Posts: n/a
 
      8th Mar 2005
Hi Greg,

Try this:

Dim drive As driveinfo
Dim aldrives As New ArrayList

drive = New driveinfo

aldrives.Add(drive)

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

HTH,

Bernie Yaeger


"GregT" <(E-Mail Removed)> wrote in message
news:C34F67C5-E848-4AFB-AF5D-(E-Mail Removed)...
>I program in C#. Is there a way to determine which of the local machine's
> logical drives are associated with CD drive(s)?



 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      8th Mar 2005
Hi Again Greg,

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

Bernie

"GregT" <(E-Mail Removed)> wrote in message
news:C34F67C5-E848-4AFB-AF5D-(E-Mail Removed)...
>I program in C#. Is there a way to determine which of the local machine's
> logical drives are associated with CD drive(s)?



 
Reply With Quote
 
=?Utf-8?B?R3JlZ1Q=?=
Guest
Posts: n/a
 
      8th Mar 2005
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" <(E-Mail Removed)> wrote in message
> news:C34F67C5-E848-4AFB-AF5D-(E-Mail Removed)...
> >I program in C#. Is there a way to determine which of the local machine's
> > logical drives are associated with CD drive(s)?

>
>
>

 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      8th Mar 2005
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(drive)

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

Bernie


"GregT" <(E-Mail Removed)> wrote in message
news:704DE320-197C-4CA0-8816-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:C34F67C5-E848-4AFB-AF5D-(E-Mail Removed)...
>> >I program in C#. Is there a way to determine which of the local
>> >machine's
>> > logical drives are associated with CD drive(s)?

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?R3JlZ1Q=?=
Guest
Posts: n/a
 
      8th Mar 2005
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:

> 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(drive)
>
> The arraylist should NOW have the drive.description of drive for each drive
> in your pc. The drive.description will give you 'cd... etc'
>
> Bernie
>
>
> "GregT" <(E-Mail Removed)> wrote in message
> news:704DE320-197C-4CA0-8816-(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> >> news:C34F67C5-E848-4AFB-AF5D-(E-Mail Removed)...
> >> >I program in C#. Is there a way to determine which of the local
> >> >machine's
> >> > logical drives are associated with CD drive(s)?
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Bernie Yaeger
Guest
Posts: n/a
 
      9th Mar 2005
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.Collections

Public Class aownerdraw

Inherits System.Windows.Forms.Form

Dim drive As driveinfo

Dim aldrives As New ArrayList

Dim mgtobjectsearcher As System.Management.ManagementObjectSearcher

Dim mgtobject As System.Management.ManagementObject

+windows form designer generated code goes here

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

mgtobjectsearcher = New System.Management.ManagementObjectSearcher("select *
from win32_logicaldisk")

drive = New driveinfo

With drive

..drivedescription = "Desktop"

..driveletter = "Desktop"

..driveletter = 0

End With

aldrives.Add(drive)

Call updatedrives()

Call adddrivestocombo()

End Sub

Private Sub updatedrives()

For Each mgtobject In mgtobjectsearcher.Get()

drive = New driveinfo

Dim sdrivedescription As String = ""

sdrivedescription = mgtobject.Properties("DeviceID").Value

drive.driveletter = sdrivedescription

sdrivedescription &= "\ " & mgtobject.Properties("Description").Value

If IsNothing(mgtobject.Properties("Size").Value) Then

sdrivedescription &= " Not Available"

Else

sdrivedescription &= " " & mgtobject.Properties("VolumeName").Value

End If

drive.drivedescription = sdrivedescription

Select Case Convert.ToInt16(mgtobject.Properties("DriveType").Value)

Case 0 : drive.driveimage = 6

Case 1 : drive.driveimage = 6

Case 2 : drive.driveimage = 1

Case 3 : drive.driveimage = 2

Case 4 : drive.driveimage = 4

Case 5 : drive.driveimage = 3

Case 6 : drive.driveimage = 0

End Select

If (drive.driveimage = 4) Then

If sdrivedescription.IndexOfAny("Not Available") > 0 Then

drive.driveimage = 5

End If

End If

aldrives.Add(drive)

Next

End Sub

Private Sub adddrivestocombo()

Dim ddrive As driveinfo

Dim i As Integer

For Each ddrive In aldrives

cbdrives.Items.Add("")

Next

If aldrives.Count > 0 Then

cbdrives.SelectedIndex = 0

End If

End Sub

Private Sub cbdrives_DrawItem(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles cbdrives.DrawItem

e.DrawBackground()

e.DrawFocusRectangle()

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.Index)

Dim sdrivedescription As String = ddrive.drivedescription

Dim idriveimage As Integer = ddrive.driveimage

Dim bmdrivebmp As Bitmap = ildrives.Images(idriveimage)

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

Dim sformat As StringFormat = StringFormat.GenericTypographic

Dim itemheight As Integer = cbdrives.ItemHeight

e.DrawBackground()

e.DrawFocusRectangle()

e.Graphics.DrawImage(bmdrivebmp, ioffset, e.Bounds.Top + (itemheight -
bmdrivebmp.Height) \ 2)

If (e.State And DrawItemState.Selected) Then

abrush = System.Drawing.Brushes.White

End If

sformat.LineAlignment = StringAlignment.Center

e.Graphics.DrawString(sdrivedescription, e.Font, abrush, (20 + ioffset),
e.Bounds.Top + (e.Bounds.Height \ 2), sformat)

End Sub

End Class

Friend Class driveinfo

Dim m_driveletter As String = ""

Dim m_drivedescription 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 drivedescription() As String

Get

Return m_drivedescription

End Get

Set(ByVal Value As String)

m_drivedescription = 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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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(drive)
>
> The arraylist should NOW have the drive.description of drive for each
> drive
> in your pc. The drive.description will give you 'cd... etc'
>
> Bernie
>
>
> "GregT" <(E-Mail Removed)> wrote in message
> news:704DE320-197C-4CA0-8816-(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>>> news:C34F67C5-E848-4AFB-AF5D-(E-Mail Removed)...
>>> >I program in C#. Is there a way to determine which of the local
>>> >machine's
>>> > logical drives are associated with CD drive(s)?
>>>
>>>
>>>

>
>



 
Reply With Quote
 
=?Utf-8?B?R3JlZ1Q=?=
Guest
Posts: n/a
 
      9th Mar 2005
Thanks Bernie,

it's much clearer now.

"Bernie Yaeger" wrote:

> 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.Collections
>
> Public Class aownerdraw
>
> Inherits System.Windows.Forms.Form
>
> Dim drive As driveinfo
>
> Dim aldrives As New ArrayList
>
> Dim mgtobjectsearcher As System.Management.ManagementObjectSearcher
>
> Dim mgtobject As System.Management.ManagementObject
>
> +windows form designer generated code goes here
>
> Private Sub aownerdraw_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
> mgtobjectsearcher = New System.Management.ManagementObjectSearcher("select *
> from win32_logicaldisk")
>
> drive = New driveinfo
>
> With drive
>
> ..drivedescription = "Desktop"
>
> ..driveletter = "Desktop"
>
> ..driveletter = 0
>
> End With
>
> aldrives.Add(drive)
>
> Call updatedrives()
>
> Call adddrivestocombo()
>
> End Sub
>
> Private Sub updatedrives()
>
> For Each mgtobject In mgtobjectsearcher.Get()
>
> drive = New driveinfo
>
> Dim sdrivedescription As String = ""
>
> sdrivedescription = mgtobject.Properties("DeviceID").Value
>
> drive.driveletter = sdrivedescription
>
> sdrivedescription &= "\ " & mgtobject.Properties("Description").Value
>
> If IsNothing(mgtobject.Properties("Size").Value) Then
>
> sdrivedescription &= " Not Available"
>
> Else
>
> sdrivedescription &= " " & mgtobject.Properties("VolumeName").Value
>
> End If
>
> drive.drivedescription = sdrivedescription
>
> Select Case Convert.ToInt16(mgtobject.Properties("DriveType").Value)
>
> Case 0 : drive.driveimage = 6
>
> Case 1 : drive.driveimage = 6
>
> Case 2 : drive.driveimage = 1
>
> Case 3 : drive.driveimage = 2
>
> Case 4 : drive.driveimage = 4
>
> Case 5 : drive.driveimage = 3
>
> Case 6 : drive.driveimage = 0
>
> End Select
>
> If (drive.driveimage = 4) Then
>
> If sdrivedescription.IndexOfAny("Not Available") > 0 Then
>
> drive.driveimage = 5
>
> End If
>
> End If
>
> aldrives.Add(drive)
>
> Next
>
> End Sub
>
> Private Sub adddrivestocombo()
>
> Dim ddrive As driveinfo
>
> Dim i As Integer
>
> For Each ddrive In aldrives
>
> cbdrives.Items.Add("")
>
> Next
>
> If aldrives.Count > 0 Then
>
> cbdrives.SelectedIndex = 0
>
> End If
>
> End Sub
>
> Private Sub cbdrives_DrawItem(ByVal sender As System.Object, ByVal e As
> System.Windows.Forms.DrawItemEventArgs) Handles cbdrives.DrawItem
>
> e.DrawBackground()
>
> e.DrawFocusRectangle()
>
> 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.Index)
>
> Dim sdrivedescription As String = ddrive.drivedescription
>
> Dim idriveimage As Integer = ddrive.driveimage
>
> Dim bmdrivebmp As Bitmap = ildrives.Images(idriveimage)
>
> Dim abrush As Brush = System.Drawing.Brushes.Black
>
> Dim sformat As StringFormat = StringFormat.GenericTypographic
>
> Dim itemheight As Integer = cbdrives.ItemHeight
>
> e.DrawBackground()
>
> e.DrawFocusRectangle()
>
> e.Graphics.DrawImage(bmdrivebmp, ioffset, e.Bounds.Top + (itemheight -
> bmdrivebmp.Height) \ 2)
>
> If (e.State And DrawItemState.Selected) Then
>
> abrush = System.Drawing.Brushes.White
>
> End If
>
> sformat.LineAlignment = StringAlignment.Center
>
> e.Graphics.DrawString(sdrivedescription, e.Font, abrush, (20 + ioffset),
> e.Bounds.Top + (e.Bounds.Height \ 2), sformat)
>
> End Sub
>
> End Class
>
> Friend Class driveinfo
>
> Dim m_driveletter As String = ""
>
> Dim m_drivedescription 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 drivedescription() As String
>
> Get
>
> Return m_drivedescription
>
> End Get
>
> Set(ByVal Value As String)
>
> m_drivedescription = 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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(drive)
> >
> > The arraylist should NOW have the drive.description of drive for each
> > drive
> > in your pc. The drive.description will give you 'cd... etc'
> >
> > Bernie
> >
> >
> > "GregT" <(E-Mail Removed)> wrote in message
> > news:704DE320-197C-4CA0-8816-(E-Mail Removed)...
> >> 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" <(E-Mail Removed)> wrote in message
> >>> news:C34F67C5-E848-4AFB-AF5D-(E-Mail Removed)...
> >>> >I program in C#. Is there a way to determine which of the local
> >>> >machine's
> >>> > logical drives are associated with CD drive(s)?
> >>>
> >>>
> >>>

> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining the text mode from a variety of data types matt3542 Microsoft Excel Worksheet Functions 17 31st Jul 2008 08:01 PM
Determining Cell Types in Excel - exceptions Tim Childs Microsoft Excel Programming 5 23rd Oct 2003 04:28 AM
Re: Determining Data Types Van T. Dinh Microsoft Access VBA Modules 0 26th Sep 2003 12:41 AM
Determining Data Types Peter Microsoft Access VBA Modules 0 25th Sep 2003 09:53 PM
Determining Data Types Nancy Microsoft Access VBA Modules 0 25th Sep 2003 05:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:52 AM.