Zjištění základních adresářů Windows

Postup:
V modulu deklarujte:
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (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
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

*Každá deklarace musí být celá na samostatné řádce

Private Function GetWinDir() As String

    Dim r As Long
    Dim nSize As Long
    Dim tmp As String
   tmp = Space$(256)
   nSize = Len(tmp)
    r = GetWindowsDirectory(tmp, nSize)

    GetWinDir = TrimNull(tmp)

End Function

Public Function GetTempDir() As String

    Dim r As Long
    Dim nSize As Long
    Dim tmp As String
    tmp = Space$(256)
    nSize = Len(tmp)
    r = GetTempPath(nSize, tmp)
    GetTempDir = TrimNull(tmp)

End Function

Private Function GetSystemDir() As String

    Dim r As Long
    Dim nSize As Long
    Dim tmp As String
    tmp = Space$(256)
    nSize = Len(tmp)
    r = GetSystemDirectory(tmp, nSize)
    GetSystemDir = TrimNull(tmp)

End Function

Private Function TrimNull(item As String)

    Dim pos As Integer
    pos = InStr(item, Chr$(0))
    If pos Then
        TrimNull = Left$(item, pos - 1)
    Else
        TrimNull = item
    End If

End Function

Ve formuláři, na událost Click tlačítka:
Private Sub Command1_Click()

    Label1 = GetWinDir()
    Label2 = GetTempDir()
    Label3 = GetSystemDir()

End Sub

Spusťte projekt. Po kliknutí na tlačítko se do jednotlivých jmenovek vyplní příslušné údaje.

Zpět

Autor: The Bozena