Hvis du vil finde Windows directory kan du gøre det på følgende måde:
I et modul erklæres API:
Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Herefter kan der oprettes funktionen:
Function GetWindowsDir() As String
'-----------------------------------------------------------
' Calls the windows API to get the windows directory
'-----------------------------------------------------------
'
Dim strBuf As String
Dim intZeroPos As Integer
strBuf = Space$(255)
'
'Get the windows directory and then trim the buffer to the exact length
'returned and add a dir sep (backslash) if the API didn't return one
'
If GetWindowsDirectory(strBuf, 255) > 0 Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
strBuf = Left$(strBuf, intZeroPos - 1)
End If
If Right(strBuf, 1) <> "\" Then
strBuf = strBuf & "\"
End If
GetWindowsDir = strBuf
Else
GetWindowsDir = ""
End If
End Function