AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

How can I retrieve the path to the Windows directory?

If your project uses ini files, the best place to save them is in the Windows directory.  This tip demonstrates how to go about finding the path to the Windows directory.

Declarations

You must copy this code into the declarations section of the project.

Public Const MAX_PATH = 260

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

Code

Public Function GetWinPath()
Dim strFolder As String
Dim lngResult As Long
strFolder = String(MAX_PATH, 0)
lngResult = GetWindowsDirectory(strFolder, MAX_PATH)
If lngResult <> 0 Then
    GetWinPath = Left(strFolder, InStr(strFolder, _
    Chr(0)) - 1)
Else
    GetWinPath = ""
End If
End Function

Use

An example of how to use this function:

Call MsgBox("The Windows directory is " & GetWinPath, _
vbInformation)

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/