473,395 Members | 1,720 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,395 software developers and data experts.

Problem in accessing CD Drive in VB.Net 2.0

88 64KB
Hi everyone, I'm focusing on a real tough problem that I hav been trying
to solve since a long time. I'm trying to detect the Open or close status
of the Cd drive door. I'm using mcisendstring function to query the
status, mcisendstring("Status CDAudio Mode"). This function returns
the following values accordingly:
"not ready", "paused", "playing", and "stopped" values.

Some devices can return the additional "open", "parked", "recording",
and "seeking" values.

If there is a cd in the drive and the door is closed then it's almost easy
to identify as "status CDAudio mode" returns a value anything other
than "open". But the real problem is when the CD door is open the
value returned by the mcisendstring function is "open". Again when the
CD door is closed with no CD inside the function is returning the same
value "open". There's no way I can distinguish the CD tray status
programatically when the value returned is "open". Can anybody help
me? Is there any way other than the mcisendstring function to
query the CD door status? If yes then Plz provide me a code example.
Jul 29 '08 #1
7 1757
TTCEric
26
If you know the drive letter assigned to the drive, why not check for the existence of files?

Using My:
Expand|Select|Wrap|Line Numbers
  1. Dim szCDROM as String = "Z:\"
  2. IF My.Computer.FileSystem.GetFiles(szCDROM).Count  > 0 THEN
  3.    msgbox "Drive must be closed. I see files!"
  4. END IF 
  5.  
Although it might error out if you attempt a GetFiles on an open drive. Solution to that would be to use Try/Catch block.
Jul 29 '08 #2
Plater
7,872 Expert 4TB
and you need to know the difference between door open and door being closed without a CD?
Most things I have seen have been geared towards "is a cd in the drive or not"
Jul 29 '08 #3
TTCEric
26
Does it make sense that the 'OPEN' condition is saying yes because it is querying the hardware driver which has a much tighter criteria of what it means to be open? So, the instant you ask, it will say yes until it realizes a spin and the shell (explorer) does its part. It might be a timing thing. The object your using is reporting what it knows at the time you ask. Know what I mean?
Jul 29 '08 #4
priyamtheone
88 64KB
If you know the drive letter assigned to the drive, why not check for the existence of files?

Using My:
Expand|Select|Wrap|Line Numbers
  1. Dim szCDROM as String = "Z:\"
  2. IF My.Computer.FileSystem.GetFiles(szCDROM).Count  > 0 THEN
  3.    msgbox "Drive must be closed. I see files!"
  4. END IF 
  5.  
Although it might error out if you attempt a GetFiles on an open drive. Solution to that would be to use Try/Catch block.
I don't hav any problem while there's a cd inside. The problem lies when there's no media in there. In that case using the code U provided will return 'False' i.e. no file(s) found, regardless of the cd door is open or closed. The problem still lies b'coz It won't tell me whether the tray is opened or not.
Aug 1 '08 #5
Plater
7,872 Expert 4TB
I don't hav any problem while there's a cd inside. The problem lies when there's no media in there. In that case using the code U provided will return 'False' i.e. no file(s) found, regardless of the cd door is open or closed. The problem still lies b'coz It won't tell me whether the tray is opened or not.
Well I did a LOT of playing around with this stuff and I couldn't figure a good way to determine if the tray was open or not. I would say is what you could do is force the tray to be either open or closed (i.e. send the eject signal probably be the best since some drives aren't capable of retracting the tray)
Aug 1 '08 #6
priyamtheone
88 64KB
Well I did a LOT of playing around with this stuff and I couldn't figure a good way to determine if the tray was open or not. I would say is what you could do is force the tray to be either open or closed (i.e. send the eject signal probably be the best since some drives aren't capable of retracting the tray)
Well that's wut I hav thought at last. It seems there's no other option. I'm forcing the door to be opened if the status returned is OPEN. Thanx anyway to all of U for ur knowledgeshare. Regards.
Sep 1 '08 #7
Jerrod
1
I too have been writing an app that deals with exactly the issue the original author faces. When my application loads, I force the CD drive door closed, then set the application state for the drawer to closed. From there I can manage the door from within the app.

However, this approach would never work for a casual user because if they manually open the door, the app is now out of sync with the true state of the drive. Proper control, and the integrity of information displayed in the app, is lost.

I have a feeling we might be out of luck as far as an easy way. If you right-click on a CD drive in ((My)Computer)Windows Explorer, the option to open the drawer is 'eject'. If you right-click on it when the door is open, the option does not change. I think it's unlikely the language provides functionality the operating system does not afford itself.
Aug 29 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Fazer | last post by:
Hello, I have a MP3 and I want to access the songs in them. I was wondering if Python could help me do that. I understand that this can be done using Linux by mountig it as a file system, but...
1
by: Jon1996 | last post by:
How do you access the volume label for a hard drive through C#? I am very much a beginner with C# at the moment and am developing a windows explorer program to help me learn. I have tried the...
1
by: Max Baki via .NET 247 | last post by:
I all, i've write a sample ftp Windows service which download files and copy them on remote share or remote mapped drive (the service works fine on local drives). This part of code is the...
1
by: mbah Sumani via .NET 247 | last post by:
(Type your message here) I Think it's the stupidness of Windows. Why the service can't access network drive but console apps or windows application can do it? So my suggestion is make the program...
2
by: Kevin Gabbert | last post by:
Hiya. I'm running vb.net 2003 on a virtual machine, and I have my source files located on the network. 256 megs virtual ram, MY machine has 1,000 megs ram. however, when I work for a period...
29
by: faq | last post by:
Hello- My computer came with a 40GB Maxtor DiamondPlus hard disk drive. I added an 80GB Maxtor DiamondPlus drive as a slave on the same IDE ATA cable, but the BIOS doesn't detect the new drive....
1
by: martin lanny | last post by:
My application should periodically connect to multiple network drives to see if the certain files were created. I would do this to retrieve the list of files in UNC path //server1/backup/: ...
1
by: priyamtheone | last post by:
Hi friends, I have got two problems while accessing cd drives. FIRSTLY: I want a code example of how to detect whether the cd drive of my machine is opened or closed. SECONDLY: I'm trying to...
2
by: =?ISO-8859-1?B?RulybmFz?= | last post by:
Hey all, I have a URGENT problem and I hope someone could help me... scenery: I have a windows app, coded using C# (framework 1.1 - VS2003)... The exe and dlls of the app is are stored in a...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.