[SHELL32]
[reactos.git] / dll / win32 / shell32 / shellreg.cpp
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 "precomp.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(shell);
24
25 /*************************************************************************
26 * SHRegOpenKeyA [SHELL32.506]
27 *
28 */
29 EXTERN_C HRESULT WINAPI SHRegOpenKeyA(
30 HKEY hKey,
31 LPSTR lpSubKey,
32 PHKEY phkResult)
33 {
34 TRACE("(%p, %s, %p)\n", hKey, debugstr_a(lpSubKey), phkResult);
35 return RegOpenKeyA(hKey, lpSubKey, phkResult);
36 }
37
38 /*************************************************************************
39 * SHRegOpenKeyW [SHELL32.507] NT 4.0
40 *
41 */
42 EXTERN_C HRESULT WINAPI SHRegOpenKeyW (
43 HKEY hkey,
44 LPCWSTR lpszSubKey,
45 PHKEY retkey)
46 {
47 WARN("%p %s %p\n",hkey,debugstr_w(lpszSubKey),retkey);
48 return RegOpenKeyW( hkey, lpszSubKey, retkey );
49 }
50
51 /*************************************************************************
52 * SHRegQueryValueA [SHELL32.508]
53 *
54 */
55 EXTERN_C HRESULT WINAPI SHRegQueryValueA(HKEY hkey, LPSTR lpSubKey, LPSTR lpValue, LPDWORD lpcbValue)
56 {
57 TRACE("(%p %s %p %p)\n", hkey, debugstr_a(lpSubKey), lpValue, lpcbValue);
58 return RegQueryValueA(hkey, lpSubKey, lpValue, (LONG*)lpcbValue);
59 }
60
61 /*************************************************************************
62 * SHRegQueryValueExA [SHELL32.509]
63 *
64 */
65 EXTERN_C HRESULT WINAPI SHRegQueryValueExA(
66 HKEY hkey,
67 LPSTR lpValueName,
68 LPDWORD lpReserved,
69 LPDWORD lpType,
70 LPBYTE lpData,
71 LPDWORD lpcbData)
72 {
73 TRACE("%p %s %p %p %p %p\n", hkey, lpValueName, lpReserved, lpType, lpData, lpcbData);
74 return RegQueryValueExA (hkey, lpValueName, lpReserved, lpType, lpData, lpcbData);
75 }
76
77 /*************************************************************************
78 * SHRegQueryValueW [SHELL32.510] NT4.0
79 *
80 */
81 EXTERN_C HRESULT WINAPI SHRegQueryValueW(
82 HKEY hkey,
83 LPWSTR lpszSubKey,
84 LPWSTR lpszData,
85 LPDWORD lpcbData )
86 {
87 WARN("%p %s %p %p semi-stub\n",
88 hkey, debugstr_w(lpszSubKey), lpszData, lpcbData);
89 return RegQueryValueW( hkey, lpszSubKey, lpszData, (LONG*)lpcbData );
90 }
91
92 /*************************************************************************
93 * SHRegQueryValueExW [SHELL32.511] NT4.0
94 *
95 * FIXME
96 * if the datatype REG_EXPAND_SZ then expand the string and change
97 * *pdwType to REG_SZ.
98 */
99 EXTERN_C HRESULT WINAPI SHRegQueryValueExW (
100 HKEY hkey,
101 LPWSTR pszValue,
102 LPDWORD pdwReserved,
103 LPDWORD pdwType,
104 LPVOID pvData,
105 LPDWORD pcbData)
106 {
107 DWORD ret;
108 WARN("%p %s %p %p %p %p semi-stub\n",
109 hkey, debugstr_w(pszValue), pdwReserved, pdwType, pvData, pcbData);
110 ret = RegQueryValueExW ( hkey, pszValue, pdwReserved, pdwType, (LPBYTE)pvData, pcbData);
111 return ret;
112 }
113
114 /*************************************************************************
115 * SHRegDeleteKeyA [SHELL32.?]
116 */
117 HRESULT WINAPI SHRegDeleteKeyA(
118 HKEY hkey,
119 LPCSTR pszSubKey)
120 {
121 FIXME("hkey=%p, %s\n", hkey, debugstr_a(pszSubKey));
122 return 0;
123 }
124
125 /*************************************************************************
126 * SHRegDeleteKeyW [SHELL32.512]
127 */
128 EXTERN_C HRESULT WINAPI SHRegDeleteKeyW(
129 HKEY hkey,
130 LPCWSTR pszSubKey)
131 {
132 FIXME("hkey=%p, %s\n", hkey, debugstr_w(pszSubKey));
133 return 0;
134 }
135
136 /*************************************************************************
137 * SHRegCloseKey [SHELL32.505] NT 4.0
138 */
139 EXTERN_C HRESULT WINAPI SHRegCloseKey (HKEY hkey)
140 {
141 TRACE("%p\n",hkey);
142 return RegCloseKey( hkey );
143 }
144
145 /*************************************************************************
146 * SHCreateSessionKey [SHELL32.723]
147 */
148 EXTERN_C HRESULT
149 WINAPI
150 SHCreateSessionKey(REGSAM samDesired, PHKEY phKey)
151 {
152 HRESULT hr = S_OK;
153 static WCHAR wszSessionKey[256];
154 LONG Error;
155
156 if (!wszSessionKey[0]) // FIXME: Critical Section
157 {
158 HANDLE hToken;
159
160 if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken))
161 {
162 TOKEN_STATISTICS Stats;
163 DWORD ReturnLength;
164
165 if (GetTokenInformation(hToken, TokenStatistics, &Stats, sizeof(Stats), &ReturnLength))
166 {
167 swprintf(wszSessionKey,
168 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\%08x%08x",
169 Stats.AuthenticationId.HighPart, Stats.AuthenticationId.LowPart);
170 }
171 else
172 hr = HRESULT_FROM_WIN32(GetLastError());
173
174 CloseHandle(hToken);
175 }
176 else
177 hr = HRESULT_FROM_WIN32(GetLastError());
178 }
179
180 if(SUCCEEDED(hr))
181 {
182 Error = RegCreateKeyExW(HKEY_LOCAL_MACHINE, wszSessionKey, 0, NULL,
183 REG_OPTION_VOLATILE, samDesired, NULL, phKey, NULL);
184 if (Error != ERROR_SUCCESS)
185 hr = HRESULT_FROM_WIN32(Error);
186 }
187
188 return hr;
189 }