A Quick Way to Find Out Whether CD-ROM Drives Can Read and Write

If you have many PCs to maintain, even checking something as simple as whether their CD-ROM drives are read-only or read/write can be a real chore. Here's a script that you can use to make this task less time-consuming.

ITPro Today

April 17, 2007

3 Min Read
ITPro Today logo in a gray background | ITPro Today


My organization has more than 600 PCs. Until recently, about 20 percent of those PCs were shared machines. Often, the shared machines had been placed in departments so that employees could use the machines' CD-RW drives, which had been installed for that purpose. However, we have since upgraded the employees' PCs with better hardware, including CD-RW drives. So, employees rarely used the shared machines.

We recently decided to remove the unused shared machines to increase resource utilization and tighten security. But before we could remove the shared PCs set up for writing CD-ROMs and reassign their hardware, we had to determine which shared PCs fell into this category. (Some shared PCs exist for other purposes and those PCs needed to remain.)Thus, I wrote a script, cdromtype.vbs, to check whether each shared machine's CD-ROM drive—including any external USB CD-ROM drive—was read-only or read/write.

I wrote cdromtype.vbs to run on Windows XP and later. Before running this script, you need to create a text file that specifies the PCs to check. Put each machine's name on a separate line and save this input file in the same directory as the script.

To launch the script, open a cmd.exe window and type

 cscript cdromtype.vbs drive:filename

where drive:filename specifies the input file's pathname. For example, if you named the input file mypclist.txt and saved it on the C drive, you'd use the command

 cscript cdromtype.vbs c:mypclist.txt 

Note that this command is assuming your default script host is WScript. If CScript is your default host, you'd leave off the cscript keyword.

Listing 1 shows the heart of cdromtype.vbs. (You can download the entire script by clicking the Download the Code Here button.) After obtaining the input file's pathname from the command line, the script checks for the existence of the input file. If the input file doesn't exist, the script displays an error message and quits.

If the input file exists, the script displays the message, This might take several minutes if you have many machines. The script then creates and opens the text file in which it will write its results, as callout A in Listing 1 shows. By default, the output file is named cdromtype.txt and is stored on the C drive. If you want to use a different filename and location, you need to replace c:cdromtype.txt with your pathname.

Next, the script opens the input file and reads the machine's names into a Dictionary object. For each PC in the Dictionary object, the script calls the isOnline function to check to see whether the PC is online. If the PC is offline, the script writes that information in the output file. If the PC is online, the script calls the cdrom function. The cdrom function uses Windows Management Instrumentation's (WMI's) Win32_CDROMDrive class to determine whether the PC's CD-ROM drives are read-only or read/write. The script then writes that PC's CD-ROM information to the output file. Figure 1 shows an example of what the output file looks like.

Share Your Scripting Experiences


Share your scripting discoveries, comments, solutions to problems, and experiences with products. Email your contributions to [email protected]. Please include your full name and phone number. We edit submissions for style, grammar, and length. If we print your submission, you’ll get $100.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like