越俎代庖,代码:Private Declare Function SHGetValueStr Lib "Shlwapi.dll" Alias "SHGetValueA" (ByVal hkey As Long, ByVal pszSubKey As String, ByVal pszValue As String, pdwType As Long, ByVal pvData As String, pcbData As Long) As Long
Private Declare Function SHGetValueLng Lib "Shlwapi.dll" Alias "SHGetValueA" (ByVal hkey As Long, ByVal pszSubKey As String, ByVal pszValue As String, pdwType As Long, pvData As Any, pcbData As Long) As LongConst REG_SZ = 1                         ' Unicode nul terminated string
Const HKEY_CURRENT_USER = &H80000001Private Sub Command1_Click()
    Dim astr As String * 256
    
    SHGetValueStr HKEY_CURRENT_USER, "Environment", "TEMP", REG_SZ, astr, 256
    Debug.Print astr
End Sub上面的代码是获得字符串类型数据的。代码是获得HKEY_CURRENT_USER\Environment
下TEMP键值的值。