Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleFind the Windows directory and system drive
Keywordswindows directory, system drive
CategoriesFiles and Directories, Tips and Tricks, Windows, API
 
Use the GetWindowsDirectory API function to get the Windows directory. The leftmost character will give you the drive letter.
 
' Return the Windows directory.
Private Function WindowsDirectory() As String
Dim windows_dir As String
Dim length As Long

    ' Get the Windows directory.
    windows_dir = Space$(MAX_PATH)
    length = GetWindowsDirectory(windows_dir, _
        Len(windows_dir))
    WindowsDirectory = Left$(windows_dir, length)
End Function

' Return the Windows directory's drive letter.
Private Function SystemDrive() As String
    SystemDrive = Left$(WindowsDirectory(), 1)
End Function
 
(Based on advice from Michael Hålling posted to the VB Helper Q and A forum http://www.topica.com/lists/VBHelperQA/read.)
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated