473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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)?
Jul 21 '05 #1
7 1880
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" <Gr***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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)?

Jul 21 '05 #2
Hi Again Greg,

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

Bernie

"GregT" <Gr***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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)?

Jul 21 '05 #3
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" <Gr***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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)?


Jul 21 '05 #4
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" <Gr***@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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" <Gr***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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)?


Jul 21 '05 #5
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" <Gr***@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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" <Gr***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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)?


Jul 21 '05 #6
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" <be*****@cherwellinc.com> wrote in message
news:eh**************@tk2msftngp13.phx.gbl...
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" <Gr***@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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" <Gr***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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)?


Jul 21 '05 #7
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" <be*****@cherwellinc.com> wrote in message
news:eh**************@tk2msftngp13.phx.gbl...
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" <Gr***@discussions.microsoft.com> wrote in message
news:70**********************************@microsof t.com...
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" <Gr***@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.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)?



Jul 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Luca | last post by:
I have the following problem: I'm developing a system where there are some processes that communicate each other via message queues; the message one process can send to another process is as...
7
by: Jean-David Beyer | last post by:
I have six hard drives (4 SCSI and 2 EIDE) on my main machine with parts of a database on each drive. The main index is on one SCSI drive all to itself. The main data are on the other three SCSI...
10
by: Orion | last post by:
Hey, I was wondering if it was possible to determine if you hit 'EOF' using fseek? I'm using fseek to traverse through the file from start to end and capturing the data into a linked list...
0
by: Robert Munroe | last post by:
I am posting this because I couldn't find anything on the subject on Usenet. Thanks to my good friend Oliver for the tip! Tested and works on XP Pro. using System; using...
2
by: Dan | last post by:
Does anyone know how to determine the physical hard drive serial number? I found a GetVolumeInformation function in C++ but wanted a comparable function in VB.net or C#. Thanks Dan Shanyfelt
1
by: Stephanie Doherty | last post by:
Hello World, I am using Visual C++.Net Ver 6 and am hoping to find out how to determine the share name/UNC path that is associated with a specific drive letter. I've looked at the Drive Object...
7
by: GregT | last post by:
I program in C#. Is there a way to determine which of the local machine's logical drives are associated with CD drive(s)?
2
by: theinvisibleGhost | last post by:
Subject says it all really. I'm being passed a string, and I'm wondering if theres an easy way to determine what exactly the string points at? Cheers Chris.
23
by: Rotsey | last post by:
Hi, I am writing an app that scans hard drives and logs info about every fine on the drive. The first iteration of my code used a class and a generic list to store the data and rhis took...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.