Obtener la carpeta System (Visual Basic)
Visual Basic 13 agosto 2007
Public Declare Function GetSystemDirectory Lib “kernel32″ _
Alias “GetSystemDirectoryA” _
(ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Public Declare Function GetWindowsDirectory Lib “kernel32″ _
Alias “GetWindowsDirectoryA” _
(ByVal lpBuffer As String, _
ByVal nSize As Long) As Long
Public Declare Function GetTempPath Lib “kernel32″ _
Alias “GetTempPathA” _
(ByVal nSize As Long, _
ByVal lpBuffer As String) As Long
‘————————
Option Explicit
Private Sub Command1_Click()
‘call the wrapper functions
Label1.Caption = GetWinDir()
Label2.Caption = GetTempDir()
Label3.Caption = GetSystemDir()
End Sub
Private Function GetWinDir() As String
Dim nSize As Long
Dim tmp As String
‘pad the string for the return value and
‘set nSize equal to the size of the string
tmp = Space$(256)
nSize = Len(tmp)
‘call the API
Call GetWindowsDirectory(tmp, nSize)
‘trim off the trailing null added by the API
GetWinDir = TrimNull(tmp)
End Function
Public Function GetTempDir() As String
Dim nSize As Long
Dim tmp As String
tmp = Space$(256)
nSize = Len(tmp)
Call GetTempPath(nSize, tmp)
GetTempDir = TrimNull(tmp)
End Function
Private Function GetSystemDir() As String
Dim nSize As Long
Dim tmp As String
tmp = Space$(256)
nSize = Len(tmp)
Call GetSystemDirectory(tmp, nSize)
GetSystemDir = TrimNull(tmp)
End Function
Private Function TrimNull(item As String)
Dim pos As Integer
‘double check that there is a chr$(0) in the string
pos = InStr(item, Chr$(0))
If pos Then
TrimNull = Left$(item, pos – 1)
Else: TrimNull = item
End If
End Function
Vota este artículo:
Posts anterior y posterior:
Posts Relacionados:
- Previo: « Devuelve la ruta al archivo (Visual Basic)
- Siguiente: Devuelve la versión de la app (Visual Basic) »


Comentarios Recientes