Search Tools Links Login

Get Windows, System, User and Temp Directories


Functions to get the Windows Directory, System Directory, Temp Directory, and User Directory.

Original Author: Snytax

API Declarations

Public Declare Function ExpandEnvironmentStrings Lib "kernel32" Alias "ExpandEnvironmentStringsA" (ByVal lpSrc As String, ByVal lpDst As String, ByVal nSize As Long) As Long
Public Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Public Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Code

'Get the windows directory
Public Function sWindowsDirectory() as String
Dim sOut As String
sOut = Space(260)
GetWindowsDirectory sOut, 260
sOut = Left(sOut, InStr(sOut, Chr(0)) - 1)
sWindowsDirectory = sOut
End Function
'Get the system directory
Public Function sSystemDirectory() as String
Dim sOut As String
sOut = Space(260)
GetSystemDirectory sOut, 260
sOut = Left(sOut, InStr(sOut, Chr(0)) - 1)
sSystemDirectory = sOut
End Function
'Get the temp directory
Public Function sTempDirectory() as String
Dim sOut As String
sOut = Space(260)
ExpandEnvironmentStrings "%TEMP%", sOut, 260
sOut = Left(sOut, InStr(sOut, Chr(0)) - 1)
sTempDirectory = sOut
End Function
'Get the user directory
Public Function sUserDirectory() as String
Dim sOut As String
sOut = Space(260)
ExpandEnvironmentStrings "%USERPROFILE%", sOut, 260
sOut = Left(sOut, InStr(sOut, Chr(0)) - 1)
sUserDirectory = sOut
End Function

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 92 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.