CodeItBetter Programming Another VB Programming Blog

How to get Windows Directory

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'System & API - How to get Windows Directory
Option Explicit
 
Private Declare Function PathAddBackslash Lib "shlwapi.dll" Alias "PathAddBackslashA" _
    (ByVal pszPath As String) As Long
Private Declare Function GetWindowsDirectoryA Lib "kernel32" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long
 
Public Function GetWindowsDirectory() As String
    Dim s As String
    Dim I As Integer
    I = GetWindowsDirectoryA("", 0)
    s = Space(I)
    Call GetWindowsDirectoryA(s, I)
    GetWindowsDirectory = AddBackslashUsingAPI(Left$(s, I - 1))
End Function
 
Public Function AddBackslashUsingAPI(ByVal sFolder As String) As String
    sFolder = sFolder & String(1, 0)
    PathAddBackslash sFolder
    AddBackslashUsingAPI = sFolder
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.