1 /* 2 * Shell Registry Access 3 * 4 * Copyright 2000 Juergen Schmied 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 19 */ 20 21 #include <wine/config.h> 22 23 #include <stdio.h> 24 25 #define WIN32_NO_STATUS 26 #define _INC_WINDOWS 27 28 #include <windef.h> 29 #include <winbase.h> 30 #include <shlobj.h> 31 #include <shlwapi.h> 32 33 #include <wine/debug.h> 34 35 WINE_DEFAULT_DEBUG_CHANNEL(shell); 36 37 /************************************************************************* 38 * SHRegOpenKeyA [SHELL32.506] 39 * 40 */ 41 HRESULT WINAPI SHRegOpenKeyA( 42 HKEY hKey, 43 LPSTR lpSubKey, 44 PHKEY phkResult) 45 { 46 TRACE("(%p, %s, %p)\n", hKey, debugstr_a(lpSubKey), phkResult); 47 return RegOpenKeyA(hKey, lpSubKey, phkResult); 48 } 49 50 /************************************************************************* 51 * SHRegOpenKeyW [SHELL32.507] NT 4.0 52 * 53 */ 54 HRESULT WINAPI SHRegOpenKeyW ( 55 HKEY hkey, 56 LPCWSTR lpszSubKey, 57 PHKEY retkey) 58 { 59 WARN("%p %s %p\n",hkey,debugstr_w(lpszSubKey),retkey); 60 return RegOpenKeyW( hkey, lpszSubKey, retkey ); 61 } 62 63 /************************************************************************* 64 * SHRegQueryValueA [SHELL32.508] 65 * 66 */ 67 HRESULT WINAPI SHRegQueryValueA(HKEY hkey, LPSTR lpSubKey, LPSTR lpValue, LPDWORD lpcbValue) 68 { 69 TRACE("(%p %s %p %p)\n", hkey, debugstr_a(lpSubKey), lpValue, lpcbValue); 70 return RegQueryValueA(hkey, lpSubKey, lpValue, (LONG*)lpcbValue); 71 } 72 73 /************************************************************************* 74 * SHRegQueryValueExA [SHELL32.509] 75 * 76 */ 77 LONG WINAPI SHRegQueryValueExA( 78 HKEY hkey, 79 LPCSTR lpValueName, 80 LPDWORD lpReserved, 81 LPDWORD lpType, 82 LPBYTE lpData, 83 LPDWORD lpcbData) 84 { 85 TRACE("%p %s %p %p %p %p\n", hkey, lpValueName, lpReserved, lpType, lpData, lpcbData); 86 return SHQueryValueExA(hkey, lpValueName, lpReserved, lpType, lpData, lpcbData); 87 } 88 89 /************************************************************************* 90 * SHRegQueryValueW [SHELL32.510] NT4.0 91 * 92 */ 93 HRESULT WINAPI SHRegQueryValueW( 94 HKEY hkey, 95 LPWSTR lpszSubKey, 96 LPWSTR lpszData, 97 LPDWORD lpcbData ) 98 { 99 WARN("%p %s %p %p semi-stub\n", 100 hkey, debugstr_w(lpszSubKey), lpszData, lpcbData); 101 return RegQueryValueW( hkey, lpszSubKey, lpszData, (LONG*)lpcbData ); 102 } 103 104 /************************************************************************* 105 * SHRegQueryValueExW [SHELL32.511] NT4.0 106 */ 107 LONG WINAPI SHRegQueryValueExW( 108 HKEY hkey, 109 LPCWSTR pszValue, 110 LPDWORD pdwReserved, 111 LPDWORD pdwType, 112 LPVOID pvData, 113 LPDWORD pcbData) 114 { 115 TRACE("%p %s %p %p %p %p\n", 116 hkey, debugstr_w(pszValue), pdwReserved, pdwType, pvData, pcbData); 117 return SHQueryValueExW(hkey, pszValue, pdwReserved, pdwType, pvData, pcbData); 118 } 119 120 /************************************************************************* 121 * SHRegDeleteKeyW [SHELL32.512] 122 */ 123 HRESULT WINAPI SHRegDeleteKeyW( 124 HKEY hkey, 125 LPCWSTR pszSubKey) 126 { 127 FIXME("hkey=%p, %s\n", hkey, debugstr_w(pszSubKey)); 128 return 0; 129 } 130 131 /************************************************************************* 132 * SHRegCloseKey [SHELL32.505] NT 4.0 133 * 134 */ 135 HRESULT WINAPI SHRegCloseKey (HKEY hkey) 136 { 137 TRACE("%p\n",hkey); 138 return RegCloseKey( hkey ); 139 } 140 141 /************************************************************************* 142 * SHCreateSessionKey [SHELL32.723] 143 */ 144 HRESULT 145 WINAPI 146 SHCreateSessionKey(REGSAM samDesired, PHKEY phKey) 147 { 148 HRESULT hr = S_OK; 149 static WCHAR wszSessionKey[256]; 150 LONG Error; 151 152 if (!wszSessionKey[0]) // FIXME: Critical Section 153 { 154 HANDLE hToken; 155 156 if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken)) 157 { 158 TOKEN_STATISTICS Stats; 159 DWORD ReturnLength; 160 161 if (GetTokenInformation(hToken, TokenStatistics, &Stats, sizeof(Stats), &ReturnLength)) 162 { 163 swprintf(wszSessionKey, 164 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\%08x%08x", 165 Stats.AuthenticationId.HighPart, Stats.AuthenticationId.LowPart); 166 } 167 else 168 hr = HRESULT_FROM_WIN32(GetLastError()); 169 170 CloseHandle(hToken); 171 } 172 else 173 hr = HRESULT_FROM_WIN32(GetLastError()); 174 } 175 176 if(SUCCEEDED(hr)) 177 { 178 Error = RegCreateKeyExW(HKEY_LOCAL_MACHINE, wszSessionKey, 0, NULL, 179 REG_OPTION_VOLATILE, samDesired, NULL, phKey, NULL); 180 if (Error != ERROR_SUCCESS) 181 hr = HRESULT_FROM_WIN32(Error); 182 } 183 184 return hr; 185 } 186