ボタンをクリックすると CD ディスクからフォルダを開くプログラムを作成しようとしています。プログラムは CD から実行され、特定のフォルダーを開くことを目的としています。ただし、「shell "explorer...."」はドライブレターが違うので使えません。VB.NET で CD からフォルダを直接開く方法はありますか
2062 次
5 に答える
2
プログラムが CD から開始されたことがわかっている場合は簡単です。プログラムの場所を読み返すだけです:
Dim exePath As String = System.Reflection.Assembly.GetEntryAssembly().Location
Dim drive As String = System.IO.Path.GetPathRoot(exePath)
于 2010-07-17T18:36:31.800 に答える
1
たとえば、ファイルを実行したい場合: executable.exe; 光学ドライブ内 E:\executables\executable.exe")
コード:
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
于 2018-11-01T23:29:58.190 に答える
0
このリンクにはいくつかの基本的なものが含まれています。それはあなたを正しい方向に向けさせるはずです。また、コードサンプルからキーワードを取得し、MSDNを検索します。MSNには、次のステップに進むためのドキュメントとサンプルがたくさんあります。
https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-6081470.html#
編集-これを試してください...
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
于 2010-07-17T17:54:11.660 に答える
0
- システム上のすべてのドライブ文字を見つけます。
- ドライブごとに
- 特定のフォルダーが存在する場合は、それを開きます。
- ループ
于 2010-07-17T17:46:27.727 に答える