How to Get The Desktop Path
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 'System & API - How to Get The Desktop Path Option Explicit Private Const ERROR_SUCCESS = 0& Private Const HKEY_CURRENT_USER = &H80000001 Private Const SYNCHRONIZE = &H100000 Private Const READ_CONTROL = &H20000 Private Const STANDARD_RIGHTS_READ = READ_CONTROL Private Const KEY_QUERY_VALUE = &H1 Private Const KEY_ENUMERATE_SUB_KEYS = &H8 Private Const KEY_NOTIFY = &H10 Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or _ KEY_NOTIFY) And (Not SYNCHRONIZE)) Private Const REG_SZ = 1 Private Declare Function RegCloseKey& Lib "ADVAPI32.DLL" (ByVal hKey&) Private Declare Function RegOpenKeyExA& Lib "ADVAPI32.DLL" (ByVal hKey&, ByVal lpSubKey$, _ ByVal ulOptions&, ByVal samDesired&, phkResult&) Private Declare Function RegQueryValueExA& Lib "ADVAPI32.DLL" (ByVal hKey&, ByVal lpValueName$, _ ByVal lpReserved&, lpType&, lpData As Any, lpcbData&) Private Function sGetDesktop() As String Const nLG As Long = 256 Dim sValue As String * nLG Dim hKey As Long Dim nType As Long Dim nCR As Long If (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", 0, KEY_READ, hKey) = ERROR_SUCCESS) Then If (RegQueryValueExA(hKey, "Desktop", 0, nType, ByVal sValue, nLG) = ERROR_SUCCESS) Then If (nType = REG_SZ) Then sGetDesktop = Left(sValue, InStr(sValue, vbNullChar) - 1) End If End If nCR = RegCloseKey(hKey) End If End Function 'How can I call this function: Private Sub Form_Load() MsgBox "Your desktop path is " & sGetDesktop End Sub |
Related posts:
- How to Open a URL in a New IE window
- How to clear Start Menu -> Run MRU list
- How to find Windows NT registered user and organization
- How to Get Default Printer Name
- How to Save/Load data from Registry
- How to Show/Hide all Desktop Icons
- How to run your application at Windows Startup
- How to check which Office Components are installed
- How to Change the desktop wallpaper
- How to list all installed apps