Answered by:
which is path to optical drive ?

Question
-
Hi!
i want to install my apps on different computers and i want to know which is path to opticale drive in general not H:\ or e:\ because is different at PC to PC
anybody knows ?
Thanx for watch
I'm sorry for my wrong English
- Edited by Doru_ro_DDapps Tuesday, September 16, 2014 8:27 AM
Tuesday, September 16, 2014 8:20 AM
Answers
-
As Cor said download the WMI Code Creator and set it like in the images below. Determine which properties you need, I selected all 49 of them. The Generated Code can be copied and pasted but since it's written for a console app needs to be altered for a Windows Form app normally. Note that PC's can have multiple Optical drives on them.
La vida loca
- Marked as answer by Doru_ro_DDapps Tuesday, September 16, 2014 3:20 PM
Tuesday, September 16, 2014 11:48 AM -
You should also be able to simply enumerate the drives through System.IO.DriveInfo and return the first one of type CDROM:
Private Function GetFirstOpticalDriveLetter() As String For Each info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives If info.DriveType = IO.DriveType.CDRom Then Return info.Name End If Next Return "None" End Function
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Proposed as answer by Mr. Monkeyboy Tuesday, September 16, 2014 1:48 PM
- Marked as answer by Doru_ro_DDapps Tuesday, September 16, 2014 2:59 PM
Tuesday, September 16, 2014 12:38 PM -
thx to all but i need to open directory optical drive...
for example:
Process.Start("OpticleDriveLetter:\folder1\subfolder1")
Red kimble:
Private Function GetFirstOpticalDriveLetter() As String For Each info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrivesIf info.DriveType = IO.DriveType.CDRom ThenReturn info.Name End IfNext Return "None" End Function
Is good but how can i open folder after get optical drive letter?
like that: Process.Start("OpticleDriveLetter:\folder1\subfolder1") or how?
thx again!
I think Frank answered this, but:
Process.Start(System.IO.Path.Combine(GetFirstOpticalDriveLetter(), "folder1\subfolder1")
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Marked as answer by Doru_ro_DDapps Friday, September 19, 2014 5:45 AM
Wednesday, September 17, 2014 9:44 PM -
pff...
look i build thiss app for me (i repair computers) after install os start my app and install those softwares.
When i press the button with picture mozzila start link to download mozzila instaler...ok
now i want to rebuild my app for offline software installer something like original drivers cd for any motherbords.
What is unbelievable?
In my last post the code in the Button1 click event detects if the an optical drive is ready.
If so its items are added to a ListBox which for you is uncessary. However you could detect if any of those items contain the MSI name you want to use.
If so then use process.start for that item.
Apparently the code must be difficult for you to understand. So here's code that detects an MSI on CD (Drive D) and runs the installer.
I would guess you could understand this example and alter it for each of your Buttons click events to install the appropriate MSI for that button. Or maybe not.
Option Strict On Imports System.IO Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2))) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ListBox1.Items.Clear() For Each DriveInf As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives If DriveInf.DriveType = IO.DriveType.CDRom Then If DriveInf.IsReady Then Me.Text = DriveInf.RootDirectory.ToString For Each Item In My.Computer.FileSystem.GetFiles(DriveInf.RootDirectory.ToString) ListBox1.Items.Add(Item) Next For Each Item In My.Computer.FileSystem.GetDirectories(DriveInf.RootDirectory.ToString, FileIO.SearchOption.SearchAllSubDirectories) ListBox1.Items.Add(Item) For Each Fl In My.Computer.FileSystem.GetFiles(Item) ListBox1.Items.Add(" " & Fl) Next Next If File.Exists(DriveInf.RootDirectory.ToString & "Setup25.Msi") Then Process.Start(DriveInf.RootDirectory.ToString & "Setup25.Msi") Exit Sub End If End If End If Next End Sub End Class
La vida loca
- Marked as answer by Doru_ro_DDapps Friday, September 19, 2014 5:45 AM
Wednesday, September 17, 2014 10:29 PM -
Hi,
You could build your Application and just copy EXE file to the CD/DVD drive that you are using to burn your CD/DVD or if your app had other files in the Debug folder that it depends on then copy the whole Debug folder to the CD/DVD that your using to burn your files to a CD/DVD and rename the folder to whatever you want.
Then you can create an Autorun.inf file that you can copy to the root of the CD/DVD that has your EXE file or the renamed Debug folder that is going to be burned to your CD/DVD.
The AutoRun file will automatically start your Application when the CD/DVD is inserted. Here is an example of a simple AutoRun.inf file you can create using Notepad. The "open=" is the path to your application`s exe file that starts when the CD/DVD is inserted. The "icon=" is optional and is used to set the icon that is shown in the "MY Computer" directory for the CD/DVD. It can ether be a path to the icon file (.ico) or it can be set to use your application`s exe file icon as shown in this example.
Open Notepad and add the below lines and save it as "Autorun.inf" then copy it to your CD/DVD root drive.
[autorun]
open=MyProgram.exe
icon=MyProgram.exe, 0
You can read more about the different options you have for creating Autorun files at this msdn link.
Then in your application you can simply use Application.StartupPath with the Path.GetPathRoot to get the drive letter of the drive your app is being run from. Then you can just use Path.Combine to join the drive letter to the path of the exe file you want to start with the Process class. Like this.
Public Class Form1 Private OpticalDrive As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load OpticalDrive = IO.Path.GetPathRoot(Application.StartupPath) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim App1PathName As String = IO.Path.Combine(OpticalDrive, "Folder1\App1.exe") Process.Start(App1PathName) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim App2PathName As String = IO.Path.Combine(OpticalDrive, "Folder2\App2.exe") Process.Start(App2PathName) End Sub End Class
If you say it can`t be done then i`ll try it
- Marked as answer by Doru_ro_DDapps Friday, September 19, 2014 5:45 AM
Wednesday, September 17, 2014 10:49 PM
All replies
-
Use WMI to do that, here a Microsoft tool to create a program for you with that.
http://www.microsoft.com/en-us/download/details.aspx?id=8572
Success
CorTuesday, September 16, 2014 10:31 AM -
As Cor said download the WMI Code Creator and set it like in the images below. Determine which properties you need, I selected all 49 of them. The Generated Code can be copied and pasted but since it's written for a console app needs to be altered for a Windows Form app normally. Note that PC's can have multiple Optical drives on them.
La vida loca
- Marked as answer by Doru_ro_DDapps Tuesday, September 16, 2014 3:20 PM
Tuesday, September 16, 2014 11:48 AM -
You should also be able to simply enumerate the drives through System.IO.DriveInfo and return the first one of type CDROM:
Private Function GetFirstOpticalDriveLetter() As String For Each info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives If info.DriveType = IO.DriveType.CDRom Then Return info.Name End If Next Return "None" End Function
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Proposed as answer by Mr. Monkeyboy Tuesday, September 16, 2014 1:48 PM
- Marked as answer by Doru_ro_DDapps Tuesday, September 16, 2014 2:59 PM
Tuesday, September 16, 2014 12:38 PM -
thx to all but i need to open directory optical drive...
for example:
Process.Start("OpticleDriveLetter:\folder1\subfolder1")
Red kimble:
Private Function GetFirstOpticalDriveLetter() As String For Each info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrivesIf info.DriveType = IO.DriveType.CDRom ThenReturn info.Name End If Next Return "None" End Function
Is good but how can i open folder after get optical drive letter?
like that: Process.Start("OpticleDriveLetter:\folder1\subfolder1") or how?
thx again!
Tuesday, September 16, 2014 2:58 PM -
thx to all but i need to open directory optical drive...
for example:
Process.Start("OpticleDriveLetter:\folder1\subfolder1")
Red kimble:
Private Function GetFirstOpticalDriveLetter() As String For Each info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrivesIf info.DriveType = IO.DriveType.CDRom ThenReturn info.Name End IfNext Return "None" End Function
Is good but how can i open folder after get optical drive letter?
like that: Process.Start("OpticleDriveLetter:\folder1\subfolder1") or how?
thx again!
First test that the drive .IsReady. If it's not, then you'll get a runtime exception thrown.
If it is, then use System.IO.Path.Combine to form the full path of the directory you're looking for. Next test that that full path exists and, if so, then you can use Process.Start and pass in that full path.
Still lost in code, just at a little higher level.
:-)Tuesday, September 16, 2014 3:02 PM -
thx to all but i need to open directory optical drive...
for example:
Process.Start("OpticleDriveLetter:\folder1\subfolder1")
Red kimble:
Private Function GetFirstOpticalDriveLetter() As String For Each info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrivesIf info.DriveType = IO.DriveType.CDRom ThenReturn info.Name End IfNext Return "None" End Function
Is good but how can i open folder after get optical drive letter?
like that: Process.Start("OpticleDriveLetter:\folder1\subfolder1") or how?
thx again!
Your question makes no sense.
What do you mean by open folder? If you want to write a program that is like Windows Explorer which displays items like Windows Explorer then you've alot to learn. Or else you can search the net for something like "Windows Explorer VB.Net" and find a program that you can use.
This code, based on Reeds code, will display all accessable folders in an Optical Drive. And any accessable files in each folder.
It also has code to "Process.Start" a file which causes the file extensions default app to open the file. In this case the extension is .Txt and my default app for .Txt extensions is Notepad.
Option Strict On Imports System.IO Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2))) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ListBox1.Items.Clear() For Each DriveInf As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives If DriveInf.DriveType = IO.DriveType.CDRom Then If DriveInf.IsReady Then Me.Text = DriveInf.RootDirectory.ToString For Each Item In My.Computer.FileSystem.GetDirectories(DriveInf.RootDirectory.ToString, FileIO.SearchOption.SearchAllSubDirectories) ListBox1.Items.Add(Item) For Each Fl In My.Computer.FileSystem.GetFiles(Item) ListBox1.Items.Add(" " & Fl) Next Next If File.Exists(DriveInf.RootDirectory.ToString & "File to Run\WordList.Txt") Then Process.Start(DriveInf.RootDirectory.ToString & "File to Run\WordList.Txt") Exit Sub End If End If End If Next End Sub End Class
La vida loca
- Edited by Mr. Monkeyboy Wednesday, September 17, 2014 4:19 AM
Wednesday, September 17, 2014 4:13 AM -
Look this is my app and i want when i press button mozzila firefox or other button to open a .exe file on the folder where is my app which is on CD and i need command to make that. simple
Wednesday, September 17, 2014 7:39 AM -
Look this is my app and i want when i press button mozzila firefox or other button to open a .exe file on the folder where is my app which is on CD and i need command to make that. simple
WebBrowsers do not open executable files I don't believe.
La vida loca
Wednesday, September 17, 2014 10:45 AM -
pff...
look i build thiss app for me (i repair computers) after install os start my app and install those softwares.
When i press the button with picture mozzila start link to download mozzila instaler...ok
now i want to rebuild my app for offline software installer something like original drivers cd for any motherbords.
What is unbelievable?
Wednesday, September 17, 2014 2:23 PM -
thx to all but i need to open directory optical drive...
for example:
Process.Start("OpticleDriveLetter:\folder1\subfolder1")
Red kimble:
Private Function GetFirstOpticalDriveLetter() As String For Each info As System.IO.DriveInfo In System.IO.DriveInfo.GetDrivesIf info.DriveType = IO.DriveType.CDRom ThenReturn info.Name End IfNext Return "None" End Function
Is good but how can i open folder after get optical drive letter?
like that: Process.Start("OpticleDriveLetter:\folder1\subfolder1") or how?
thx again!
I think Frank answered this, but:
Process.Start(System.IO.Path.Combine(GetFirstOpticalDriveLetter(), "folder1\subfolder1")
Reed Kimble - "When you do things right, people won't be sure you've done anything at all"
- Marked as answer by Doru_ro_DDapps Friday, September 19, 2014 5:45 AM
Wednesday, September 17, 2014 9:44 PM -
pff...
look i build thiss app for me (i repair computers) after install os start my app and install those softwares.
When i press the button with picture mozzila start link to download mozzila instaler...ok
now i want to rebuild my app for offline software installer something like original drivers cd for any motherbords.
What is unbelievable?
In my last post the code in the Button1 click event detects if the an optical drive is ready.
If so its items are added to a ListBox which for you is uncessary. However you could detect if any of those items contain the MSI name you want to use.
If so then use process.start for that item.
Apparently the code must be difficult for you to understand. So here's code that detects an MSI on CD (Drive D) and runs the installer.
I would guess you could understand this example and alter it for each of your Buttons click events to install the appropriate MSI for that button. Or maybe not.
Option Strict On Imports System.IO Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2))) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ListBox1.Items.Clear() For Each DriveInf As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives If DriveInf.DriveType = IO.DriveType.CDRom Then If DriveInf.IsReady Then Me.Text = DriveInf.RootDirectory.ToString For Each Item In My.Computer.FileSystem.GetFiles(DriveInf.RootDirectory.ToString) ListBox1.Items.Add(Item) Next For Each Item In My.Computer.FileSystem.GetDirectories(DriveInf.RootDirectory.ToString, FileIO.SearchOption.SearchAllSubDirectories) ListBox1.Items.Add(Item) For Each Fl In My.Computer.FileSystem.GetFiles(Item) ListBox1.Items.Add(" " & Fl) Next Next If File.Exists(DriveInf.RootDirectory.ToString & "Setup25.Msi") Then Process.Start(DriveInf.RootDirectory.ToString & "Setup25.Msi") Exit Sub End If End If End If Next End Sub End Class
La vida loca
- Marked as answer by Doru_ro_DDapps Friday, September 19, 2014 5:45 AM
Wednesday, September 17, 2014 10:29 PM -
Hi,
You could build your Application and just copy EXE file to the CD/DVD drive that you are using to burn your CD/DVD or if your app had other files in the Debug folder that it depends on then copy the whole Debug folder to the CD/DVD that your using to burn your files to a CD/DVD and rename the folder to whatever you want.
Then you can create an Autorun.inf file that you can copy to the root of the CD/DVD that has your EXE file or the renamed Debug folder that is going to be burned to your CD/DVD.
The AutoRun file will automatically start your Application when the CD/DVD is inserted. Here is an example of a simple AutoRun.inf file you can create using Notepad. The "open=" is the path to your application`s exe file that starts when the CD/DVD is inserted. The "icon=" is optional and is used to set the icon that is shown in the "MY Computer" directory for the CD/DVD. It can ether be a path to the icon file (.ico) or it can be set to use your application`s exe file icon as shown in this example.
Open Notepad and add the below lines and save it as "Autorun.inf" then copy it to your CD/DVD root drive.
[autorun]
open=MyProgram.exe
icon=MyProgram.exe, 0
You can read more about the different options you have for creating Autorun files at this msdn link.
Then in your application you can simply use Application.StartupPath with the Path.GetPathRoot to get the drive letter of the drive your app is being run from. Then you can just use Path.Combine to join the drive letter to the path of the exe file you want to start with the Process class. Like this.
Public Class Form1 Private OpticalDrive As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load OpticalDrive = IO.Path.GetPathRoot(Application.StartupPath) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim App1PathName As String = IO.Path.Combine(OpticalDrive, "Folder1\App1.exe") Process.Start(App1PathName) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim App2PathName As String = IO.Path.Combine(OpticalDrive, "Folder2\App2.exe") Process.Start(App2PathName) End Sub End Class
If you say it can`t be done then i`ll try it
- Marked as answer by Doru_ro_DDapps Friday, September 19, 2014 5:45 AM
Wednesday, September 17, 2014 10:49 PM