AW: How to detect a CD Drive / write permissions?

Ken Ray kray at sonsothunder.com
Sun Dec 7 02:53:45 EST 2008


> Mac and Win. Obviously there is no native Rev function, do you have snippets
> how to ask the shell for it?

For Mac, you need to use the "system_profiler" shell command, pass it one of
the data types you're interested in, and then parse the result. I'm not sure
what Mac OSes you need to support, but here's the basics:

1) Get a list of existing datatypes on the current machine so you can know
which ones to check in subsequent commands:

    put shell("system_profiler -listDataTypes") into tTypesList

2) You'll need to look at a handful of the data types. For example, my setup
right now is a MacBook Pro with two external drives attached via USB and a
built in R/W CD/DVD. On *my* machine, you query:

  - the "SPParallelATADataType" to get data on any mounted CD or DVD in the
drive;

  - the "SPSerialATADataType" to get data on my internal hard drive;

  - and the "SPUSBDataType" to get data on the external hard drives.

The way you would call it is:

  put shell("system_profiler SPUSBDataType") into tUSBData

... and then parse that. You can get a bunch of data types together, but it
may make parsing difficult. But the way to do that is:

  put shell("system_profiler SPUSBDataType SPSerialATADataType") into tData

3) You can get more info on this command by typing "man system_profiler" in
the terminal on OS X.

As to Windows, there is a "driveType" property that you can query with a
VBScript, but it uses the "Scripting.FileSystemObject" object, which may
trigger virus protection software installed on the target machine. But if
you want to use it, here's the VBScript:
-------------
Dim tFSO, tDrive, tType, tDrivePath

'This is where you put in the drive letter you've parsed from a file path
Set tDrivePath = "C:"

Set tFSO = CreateObject("Scripting.FileSystemObject")
Set tDrive = tFSO.GetDrive( tDrivePath)
Select Case tDrive.DriveType
    Case 0: tType = "Unknown"
    Case 1: tType = "Removable"
    Case 2: tType = "Fixed"
    Case 3: tType = "Network"
    Case 4: tType = "CD-ROM"
    Case 5: tType = "RAM Disk"
End Select

' If you're using Rev 3.0 or later, use this final line:
result = tType

' If you're using Rev 2.9 or earlier, use this line instead:
WScript.Echo tType
----------------

There may be another way to run this without using the
Scripting.FileSystemObject, but the only other way I've used is to wrap this
code into a DLL, register the DLL and then call on the *DLL* from VBScript.

Anyway, hope this helps,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/





More information about the use-livecode mailing list