CodeItBetter Programming Another VB Programming Blog

How to get System 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 System Directory
Option Explicit
 
Private Declare Function PathAddBackslash Lib "shlwapi.dll" Alias "PathAddBackslashA" _
    (ByVal pszPath As String) As Long
Private Declare Function GetSystemDirectoryA Lib "kernel32" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long
 
Public Function GetSystemDirectory() As String
    Dim sSystemPath As String
    Dim I As Integer
    I = GetSystemDirectoryA("", 0)
    sSystemPath = Space(I)
    Call GetSystemDirectoryA(sSystemPath, I)
    GetSystemDirectory = AddBackslashUsingAPI(Left$(sSystemPath, 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.