An "AutoRun" is just a simple text file that is saved in the root of the DVD or CD itself which contains the exe file you want to run when the DVD or CD is inserted. A VB.Net program would not be needed to run the exe on the DVD or CD.
You can find info on creating an AutoRun.inf file at the links below.
Msdn - Creating an AutoRun-Enabled Application Wikipedia - Autorun.inf
However, if you actually want to run an exe on a Dvd or Cd from your vb.net application and you want your application to find the Dvd-Rom or Cd-Rom which contains the exe, then you can use the
DriveInfo Class to do that.
You can iterate through all the drives that are CD/DVD types and look for the filename of your exe file on them. For example...
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
-
For Each di As IO.DriveInfo In IO.DriveInfo.GetDrives 'iterate through all the drives avaiable
-
If di.IsReady AndAlso di.DriveType = IO.DriveType.CDRom Then 'check if the drive is ready and it is a CDRom type
-
Dim ExeToFind As String = IO.Path.Combine(di.Name, "MyExeFile.exe") 'combine the drive letter with the filename of your specific exe file
-
If IO.File.Exists(ExeToFind) Then 'check if your exe file exists on this CD/DVD
-
Process.Start(ExeToFind) 'start the exe
-
Exit For 'exe was found and started so, no need to keep looking, exit the loop
-
End If
-
End If
-
Next
-
End Sub
-
Or using the Where extension method...
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
-
Dim drive As IO.DriveInfo = IO.DriveInfo.GetDrives.Where(Function(di) di.IsReady AndAlso di.DriveType = IO.DriveType.CDRom AndAlso IO.File.Exists(di.Name & "MyExe.exe")).FirstOrDefault
-
If drive IsNot Nothing Then
-
Process.Start(drive.Name & "MyExe.exe")
-
End If
-
End Sub
-