Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
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-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated