How do I open a folder from CD drive using VB.NET?

I'm trying to write a program that opens a folder from the CD disk when a button is clicked. The program will be run from a CD, and aims to open a certain folder. However, I can't use "shell "explorer...."" because the drive letter will change between different computers. Is there a way to open the folder straight from the CD in VB.NET

It is easy if you know that your program was started from the CD. Just read the program location back:

    Dim exePath As String = System.Reflection.Assembly.GetEntryAssembly().Location
    Dim drive As String = System.IO.Path.GetPathRoot(exePath)

How do I open a folder from CD drive using VB.NET?, The program will be run from a CD, and aims to open a certain folder. However, I can't use "shell "explorer."" because the drive letter will change between  The program will be run from a CD, and aims to open a certain folder. However, I can't use "shell "explorer."" because the drive letter will change between different computers. Is there a way to open the folder straight from the CD in VB.NET

Example, if I want execute an file: executable.exe; In Optical drive E:\executables\executable.exe")

Code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim strDrives() As String

        Dim drvInof As System.IO.DriveInfo

        'Get all drives on the computer

.       strDrives = System.IO.Directory.GetLogicalDrives

        'list all the drives

        For i As Int16 = 0 To strDrives.Length

            'Get drive info

            drvInof = New System.IO.DriveInfo(strDrives(i))

            'Check if it`s CDRom

            If drvInof.DriveType = IO.DriveType.CDRom Then

                'Run exe from the CDRom

                Try

                  'here we try to run from the cdrom we found the exe

                    Process.Start(drvInof.Name & "executables\executable.exe")

                Catch ex As Exception

                    'error handle if the exe is not found or anything else

                    MessageBox.Show(ex.ToString)

                End Try

            End If

        Next

    End Sub

VB.NET - Open/Close the CD Drive, FileSystem Object , which are available in Visual Basic. See FileSystem for The ListBox contains a list of .txt files in the selected folder. Append(vbCrLf) ' Open the text file. Dim sr As by Using .NET Framework Methods  Finally: This elegant solution and tips to remove a DVD or CD from the drive is not just written for Windows 10. As you can see above in Windows 10 shot screenshot, you can open this drive flip example as a solution without hesitation also apply to earlier versions of Microsoft's Windows operating systems, no matter if it is a drive on home Windows desktop PC, an external on tablet, Surface

Visual Basic .NET: How to Browse Files, Folders, and Directories , Now open the messagedeployer folder using Windows Explorer or My Computer. • You will notice this that VB.net has automatically created the setup related  Hi, You have to use winmm.dll API //Import winmm.dll [DllImport("winmm.dll")] static extern Int32 mciSendString(String command, StringBuilder buffer, Int32 bufferSize, IntPtr hwndCallback);

This link contains some basic stuff. It should get you pointed in the right direction. Also, take keywords from the code sample and search MSDN. MSN has lots of documentation and samples that may get you to the next step.

https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6081470.html#

edit - try this...

Imports System.IO

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For Each D As DriveInfo In DriveInfo.GetDrives
            If D.DriveType = DriveType.CDRom Then
                Debug.WriteLine(D.Name)
            End If

        Next
    End Sub
End Class

Walkthrough: Manipulating Files and Directories in Visual Basic, Reads data from an open disk file into a variable. The My feature gives you better productivity and performance in file I/O operations than FileGet . For more  I use the code below to open a file, in an ACCESS application, that's saved in "C:\Schedules\" file path. The app users will start saving the spreadsheets in Microsoft OneDrive. How do I rewrite my code so that it reads the files from Microsoft OneDrive?

You can using this code:

 Dim allDrives() As DriveInfo = DriveInfo.GetDrives()

    Dim d As DriveInfo
    For Each d In allDrives
        'Console.WriteLine("Drive {0}", d.Name)
        'Console.WriteLine("  Drive type: {0}", d.DriveType)
        If d.DriveType = DriveType.CDRom Then
            If d.IsReady = True Then
                Console.WriteLine("  Volume Name: {0}", d.Name)
                Console.WriteLine("  Volume label: {0}", d.VolumeLabel)
                Console.WriteLine("  File system: {0}", d.DriveFormat)
                Console.WriteLine( _
                    "  Available space to current user:{0, 15} bytes", _
                    d.AvailableFreeSpace)

                Console.WriteLine( _
                    "  Total available space:          {0, 15} bytes", _
                    d.TotalFreeSpace)

                Console.WriteLine( _
                    "  Total size of drive:            {0, 15} bytes ", _
                    d.TotalSize)
            End If
        End If

    Next

Straight To The Point, The DriveInfo object has a DriveType property. Using the code. The simple example can be inserted into a VB.NET program or converted to C#  I am a beginner in VB.net. I am trying to write a program which will open around 300 files (which are .msg files)in a folder and extract the responses of the questions in those files. I have been able to open and extract data from one file using opentext(filename) method but I am not able to figure out how to loop through each file in the

FileSystem Class (Microsoft.VisualBasic), VB.Net - File Handling - A file is a collection of data stored in a disk with a specific name and a directory path. Directory, Helps in manipulating a directory structure. The FileMode enumerator defines various methods for opening files. I want to be able to open up a local folder on a drive by using the webpage. This drive is a server on the network but on everyones computer it is set as G:\ so i want to be able to get a file from this drive but the file name will change all the time. How can i open up a local instance of this folder right now it seems to be pulling it from

How to determine the CD/DVD (optical) drive letter, Learn how you can use Visual Basic to make a program that mounts ISO files. NET library to read and write ISO files and Virtual Machine disk files, The mounted disk contains one folder named test and one file named Open); Dim cd As New CDReader(stISO, True); Dim fileStream As Stream = _; cd. In Windows Explorer, you can right-click on a CD-Drive and select the "Eject" option to open the CD Drive. Unfortunately, there is no "Close" equivelant to Close the drive. This project builds a command-line program that lets you open or close any or all of your CD-Drives. To display the program's usage, run the program with no parameters:

VB.Net - File Handling, If you need your program to seek out a cd or dvd drive, then the System.IO.DriveInfo class is what you need. This is a very quick example that will return a list (of DriveInfo) for every Optical Drive found.

Comments
  • Does the 'drive' variable refer to the executed path or to the drive letter?
  • If the CD drive is D then drive will contain "D:\". Use Path.Combine to create the full path to the directory name.
  • Right, thanks for that, but can you provide the specific syntax for this. Thanks :)