logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 How to retrieve various system paths

Posted on
2/18/2001
Author:
Robert Gelb
Email:
Not Shown
Applies To OS:
All
Product:
5, 6



For your programming enjoyment below, we provide the code to retrieve the Windows directory, Windows System directory and Temporary directory. 

Add the following to a .BAS, .FRM or .CLS


Private Declare Function GetSystemDirectory Lib "kernel32" Alias _
    "GetSystemDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _
    "GetWindowsDirectoryA" (ByVal lpBuffer As String, _
    ByVal nSize As Long) As Long


Private Declare Function GetTempPath Lib "kernel32" Alias _
    "GetTempPathA" (ByVal nBufferLength As Long, _
    ByVal lpBuffer As String) As Long
    

'Get the Windows directory
Public Function WindowsDirectory() As String
    Dim Buffer As String * 255
    Dim Length As Long
    
    'get the path
    Length = GetWindowsDirectory(Buffer, Len(Buffer))
    
    'Length contains the number of chars returned up to the NULL
    WindowsDirectory = Left$(Buffer, Length)
End Function


'Get the Windows System directory
Public Function SystemDirectory() As String
    Dim Buffer As String * 255
    Dim Length As Long
    
    'get the path
    Length = GetSystemDirectory(Buffer, Len(Buffer))
    
    'Length contains the number of chars returned up to the NULL
    SystemDirectory = Left$(Buffer, Length)
End Function

'Get the Temp directory
Public Function TempDirectory() As String
    Dim Buffer As String * 512
    Dim Length As Long
    
    'get the path
    Length = GetTempPath(Len(Buffer), Buffer)
    
    'Length contains the number of chars returned up to the NULL
    'As a bonus, the Temp path is terminated with a slash
    TempDirectory = Left$(Buffer, Length)
   
End Function


Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By jyoti. Posted on 3/26/2006 11:57:29 AM
Hello,

I am very new commer in VB. I need to know that why in my application I have to write this code.