VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code retrieves all special folders like desktop, windows,inf,media,program files,....

by Lajili Houssem (6 Submissions)
Category: Registry
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 5th November 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code retrieves all special folders like desktop, windows,inf,media,program files,....

API Declarations


Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Public Const REG_SZ = 1 ' Unicode nul terminated String
Public Const REG_DWORD = 4 ' 32-bit number
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_SUCCESS = 0&
Const UNIT_NAME = "UTILITY"
Function getdesktoppath()
getdesktoppath = GetString(&H80000002, "software\microsoft\windows\currentversion\explorer\shell folders\", "common desktop")
End Function
Function getmydocumentpath()
getmydocumentpath = GetString(&H80000002, "software\microsoft\windows\currentversion\explorer\shell folders\", "personal")
End Function
Function getapplicationdatapath()
getapplicationdatapath = GetString(&H80000002, "software\microsoft\windows\currentversion\explorer\shell folders\", "common appdata")
End Function
Public Function GetString(hKey As Long, strPath As String, strValue As String)
Dim KeyHand As Long
Dim datatype As Long
Dim lResult As Long
Dim strBuf As String
Dim lDataBufSize As Long
Dim intZeroPos As Integer
Dim r As Long
Dim lValueType As Long
r = RegOpenKey(hKey, strPath, KeyHand)
lResult = RegQueryValueEx(KeyHand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
If lValueType = REG_SZ Then
strBuf = String(lDataBufSize, " ")
lResult = RegQueryValueEx(KeyHand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
If lResult = ERROR_SUCCESS Then
intZeroPos = InStr(strBuf, Chr$(0))
If intZeroPos > 0 Then
GetString = Left(strBuf, intZeroPos - 1)
Else
GetString = strBuf
End If
End If
End If
End Function
Function getwindowsdectory()
Set fs = CreateObject("scripting.filesystemobject")
Set getwindowsdectory = fs.getspecialfolder(0)
End Function
Function getwindowssystemdectory()
Set fs = CreateObject("scripting.filesystemobject")
Set getwindowssystemdectory = fs.getspecialfolder(1)
End Function
Function gettempdectory()
Set fs = CreateObject("scripting.filesystemobject")
Set gettempdectory = fs.getspecialfolder(2)
End Function
Function getprogramfilespath()
getprogramfilespath = GetString(&H80000002, "software\microsoft\windows\currentversion\", "programfilesdir")
End Function
Function getinfpath()
getinfpath = GetString(&H80000002, "software\microsoft\windows\currentversion\", "devicepath")
End Function
Function getmediapath()
getmediapath = GetString(&H80000002, "software\microsoft\windows\currentversion\", "mediapath")
End Function
Function getcommonprogramspath()
getcommonprogramspath = GetString(&H80000002, "software\microsoft\windows\currentversion\", "commonfilesdir")
End Function

Function getquicklunchpath()
getquicklunchpath = GetString(&H80000003, ".DEFAULT\Software\Microsoft\Windows\CurrentVersion\GrpConv\MapGroups", "Quick Launch")
End Function


Rate This code retrieves all special folders like desktop, windows,inf,media,program files,....




Download this snippet    Add to My Saved Code

This code retrieves all special folders like desktop, windows,inf,media,program files,.... Comments

No comments have been posted about This code retrieves all special folders like desktop, windows,inf,media,program files,..... Why not be the first to post a comment about This code retrieves all special folders like desktop, windows,inf,media,program files,.....

Post your comment

Subject:
Message:
0/1000 characters