Abrir archivo desde cd

Hola anders, mi nombres es julio cesar y estoy haciendo un pequeño programa pero quiero que este abra desde el cd la ruta no se como variarla dependiendo del computador, como tu sabes las particiones de disco, la cantidad de unidades de cd que posee el computador asignan una letra difrenete en cada computador, como puedo hacer para que el archivo especifico abra otro archivo pero desde el cd indiferente de la letra asignada.?
gracias.

1 Respuesta

Respuesta
1
Hay que emplear una API de Windows. Es una función de Windows, devuelve la letra del primer CD del equipo (por ejemplo D:\).
Microsoft lo explica en
http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q180/7/66.asp?id=180766&SD=MSKB&NoWebContent=1
Crea dos módulos para el siguiente código.
Saludos,
Anders
xltoday.net
? MODULO 1
?**********************************************************
Declare Function GetDriveType Lib "kernel32" Alias _
"GetDriveTypeA" (ByVal nDrive As String) As Long
Declare Function GetLogicalDriveStrings Lib "kernel32" Alias _
"GetLogicalDriveStringsA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Public Const DRIVE_CDROM As Long = 5
Function GetFirstCdRomDriveLetter() As String
' Declare variables.
Dim lDriveType As Long
Dim strDrive As String
Dim lStart As Long: lStart = 1
' Create a string to hold the logical drives.
Dim strDrives As String
strDrives = Space(150)
' Get the logial drives on the system.
' If the function fails it returns zero.
Dim lRetVal As Long
lRetVal = GetLogicalDriveStrings(150, strDrives)
' Check to see if GetLogicalDriveStrings() worked.
If lRetVal = 0 Then
' Get GetLogicalDriveStrings() failed.
GetFirstCdRomDriveLetter = vbNullString
Exit Function
End If
' Get the string that represents the first drive.
strDrive = Mid(strDrives, lStart, 3)
Do
' Test the first drive.
lDriveType = GetDriveType(strDrive)
' Check if the drive type is a CD-ROM.
If lDriveType = DRIVE_CDROM Then
' Found the first CD-ROM drive on the system.
GetFirstCdRomDriveLetter = strDrive
Exit Function
End If
' Increment lStart to next drive in the string.
lStart = lStart + 4
' Get the string that represents the first drive.
strDrive = Mid(strDrives, lStart, 3)
Loop While (Mid(strDrives, lStart, 1) <> vbNullChar)
End Function
MODULO 2
?**********************************************
Sub Letra_del_cdrom()
Dim strDriveLetter As String
' Call the GetFirstCdRomDriveLetter() and store the
' return value in strDriveLetter.
strDriveLetter = GetFirstCdRomDriveLetter()
' Display the drive letter in a message box.
?Cambia a una variable?
MsgBox strDriveLetter
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas