James883

Hi there,

does anyone know a VB2005 script which when a button "browse CD" is pressed. It opens windows explorer and opens the contents of the CD or DVD rom.

Thanks.



Re: Visual Basic General Explore a CD or DVD drive

nobugz

Try this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For drive As Integer = Asc("D") To Asc("Z")
Dim info As New System.IO.DriveInfo(Chr(drive))
If info.DriveType = IO.DriveType.CDRom Then
System.Diagnostics.Process.Start("Explorer.exe", Chr(drive) + ":\")
Exit For
End If
Next
End Sub





Re: Visual Basic General Explore a CD or DVD drive

James883

The code opens windows explorer but it opens drive "D" when theres a disk in drive "D"

but when theres not a disk in drive "D" then it will open drive "E"

Drive D is my first CD/DVD Drive

Drive E is my second CD/DVD-RW

is there another way in which it opens the drive where the CD is

so if i insert it into drive "D" it will open drive "D" in windows exporer and if i insert it into drive "E" it will open drive "E" in windows explorer even if theres a disk in drive "D"





Re: Visual Basic General Explore a CD or DVD drive

nobugz

I can't think of the Artificial Intelligence code that would be required to determine that the disk in the E: drive is preferable over the disk in the D: drive. You'll need two buttons to handle two drives.





Re: Visual Basic General Explore a CD or DVD drive

James883

cant you use somthing like this:

If

(cd in drive D)

then

Open D in explorer

end if





Re: Visual Basic General Explore a CD or DVD drive

James883

or maybe i could have a blank text file on my cd and tell the application to search for the file like (f5gfgh4d5hd4h.txt) one which would not confilt with any other file on all drives and then the drive which the file is found. open it in exporer





Re: Visual Basic General Explore a CD or DVD drive

nobugz

Use the DriveInfo.IsReady property:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For drive As Integer = Asc("D") To Asc("Z")
Dim info As New System.IO.DriveInfo(Chr(drive))
If info.DriveType = IO.DriveType.CDRom AndAlso info.IsReady Then
System.Diagnostics.Process.Start("Explorer.exe", Chr(drive) + ":\")
Exit For
End If
Next
End Sub





Re: Visual Basic General Explore a CD or DVD drive

James883

just tried it.

when theres a disk in drive D, it opens that in windows explorer.

when theres not a disk in D it opens drive E in explorer.





Re: Visual Basic General Explore a CD or DVD drive

James883

but bear in mind i am using drive E for my autorun tester





Re: Visual Basic General Explore a CD or DVD drive

nobugz

I'm running out of ideas for what you're looking for. Maybe you need Autorun. Add a file named "Autorun.inf" to the CD-ROM's root folder with this content:

[autorun]
open=explorer.exe .

For a complete description of all options, check this MSDN library topic.