Obtener directorio de Windows y System


Siempre es útil conocer el directorio de Windows y del System. Gracias a dos funciones de la API podemos saber esto :

Declaraciones :

Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Código :

Private Sub Command1_Click()

Dim Car As String * 128
Dim Longitud As Integer
Dim Es As Integer
Dim Camino As String

Longitud = 128

Es = GetWindowsDirectory(Car, Longitud)
Camino = RTrim$(LCase$(Left$(Car, Es)))
Label1.Caption = Camino

Es = GetSystemDirectory(Car, Longitud)
Camino = RTrim$(LCase$(Left$(Car, Es)))
Label2.Caption = Camino

End Sub