Alistair Leslie-Hughes : shell32: Implement SHCreateSessionKey.

Alexandre Julliard julliard at winehq.org
Fri Apr 20 17:55:42 CDT 2018


Module: wine
Branch: master
Commit: a7124722aa9f98582608f8f77b6b2f912c6149a4
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=a7124722aa9f98582608f8f77b6b2f912c6149a4

Author: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Date:   Thu Apr 19 09:59:36 2018 +0000

shell32: Implement SHCreateSessionKey.

Based on a patch by Dmitry Timoshkov.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/shell32/shellreg.c       | 25 ++++++++++++++++++++++---
 dlls/shell32/tests/shellole.c | 25 +++++++++++++++++++++----
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/dlls/shell32/shellreg.c b/dlls/shell32/shellreg.c
index 356ec4e..2ecd0af 100644
--- a/dlls/shell32/shellreg.c
+++ b/dlls/shell32/shellreg.c
@@ -33,6 +33,7 @@
 #include "winreg.h"
 
 #include "undocshell.h"
+#include "shell32_main.h"
 
 #include "wine/debug.h"
 
@@ -154,7 +155,25 @@ HRESULT WINAPI SHRegCloseKey (HKEY hkey)
  */
 HRESULT WINAPI SHCreateSessionKey(REGSAM access, HKEY *hkey)
 {
-    FIXME("stub: %d %p\n", access, hkey);
-    *hkey = NULL;
-    return E_NOTIMPL;
+    static const WCHAR session_format[] = {
+                'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
+                'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
+                'E','x','p','l','o','r','e','r','\\','S','e','s','s','i','o','n','I','n','f','o','\\','%','u',0};
+    DWORD session, ret;
+    WCHAR str[ARRAY_SIZE(session_format) + 16];
+
+    if (hkey)
+        *hkey = NULL;
+
+    if (!access)
+        return E_ACCESSDENIED;
+
+    if (!ProcessIdToSessionId(GetCurrentProcessId(), &session))
+        return E_INVALIDARG;
+
+    sprintfW(str, session_format, session);
+    TRACE("using session key %s\n", debugstr_w(str));
+
+    ret = RegCreateKeyExW(HKEY_CURRENT_USER, str, 0, NULL, REG_OPTION_VOLATILE, access, NULL, hkey, NULL);
+    return HRESULT_FROM_WIN32( ret );
 }
diff --git a/dlls/shell32/tests/shellole.c b/dlls/shell32/tests/shellole.c
index f611faf..4144f18 100644
--- a/dlls/shell32/tests/shellole.c
+++ b/dlls/shell32/tests/shellole.c
@@ -862,8 +862,15 @@ static void test_DragQueryFile(void)
 
 static void test_SHCreateSessionKey(void)
 {
+    static const WCHAR session_format[] = {
+                'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
+                'W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
+                'E','x','p','l','o','r','e','r','\\','S','e','s','s','i','o','n','I','n','f','o','\\','%','u',0};
     HKEY hkey, hkey2;
     HRESULT hr;
+    DWORD session;
+    WCHAR sessionW[(sizeof(session_format)/sizeof(WCHAR)) + 16];
+    LONG ret;
 
     if (!pSHCreateSessionKey)
     {
@@ -876,18 +883,28 @@ static void test_SHCreateSessionKey(void)
 
     hkey = (HKEY)0xdeadbeef;
     hr = pSHCreateSessionKey(0, &hkey);
-    todo_wine ok(hr == E_ACCESSDENIED, "got 0x%08x\n", hr);
+    ok(hr == E_ACCESSDENIED, "got 0x%08x\n", hr);
     ok(hkey == NULL, "got %p\n", hkey);
 
     hr = pSHCreateSessionKey(KEY_READ, &hkey);
-    todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
 
     hr = pSHCreateSessionKey(KEY_READ, &hkey2);
-    todo_wine ok(hr == S_OK, "got 0x%08x\n", hr);
-    todo_wine ok(hkey != hkey2, "got %p, %p\n", hkey, hkey2);
+    ok(hr == S_OK, "got 0x%08x\n", hr);
+    ok(hkey != hkey2, "got %p, %p\n", hkey, hkey2);
 
     RegCloseKey(hkey);
     RegCloseKey(hkey2);
+
+    /* check the registry */
+    ProcessIdToSessionId( GetCurrentProcessId(), &session);
+    if (session)
+    {
+        wsprintfW(sessionW, session_format, session);
+        ret = RegOpenKeyW(HKEY_CURRENT_USER, sessionW, &hkey);
+        ok(!ret, "key not found\n");
+        RegCloseKey(hkey);
+    }
 }
 
 static void test_dragdrophelper(void)




More information about the wine-cvs mailing list