/
shellservice.cpp
141 lines (119 loc) · 3.82 KB
/
shellservice.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* ReactOS Explorer
*
* Copyright 2014 - David Quintana
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "precomp.h"
static int CALLBACK InitializeAllCallback(void* pItem, void* pData)
{
IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
HRESULT * phr = reinterpret_cast<HRESULT *>(pData);
TRACE("Initializing SSO %p\n", pOct);
*phr = pOct->Exec(&CGID_ShellServiceObject, OLECMDID_NEW, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
return SUCCEEDED(*phr);
}
static int CALLBACK ShutdownAllCallback(void* pItem, void* pData)
{
IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
TRACE("Shutting down SSO %p\n", pOct);
pOct->Exec(&CGID_ShellServiceObject, OLECMDID_SAVE, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
return TRUE;
}
static int CALLBACK DeleteAllEnumCallback(void* pItem, void* pData)
{
IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
TRACE("Releasing SSO %p\n", pOct);
pOct->Release();
return TRUE;
}
HRESULT InitShellServices(HDPA * phdpa)
{
IOleCommandTarget * pOct;
HKEY hkey;
CLSID clsid;
WCHAR name[MAX_PATH];
WCHAR value[MAX_PATH];
DWORD type;
LONG ret;
HDPA hdpa;
HRESULT hr = S_OK;
int count = 0;
*phdpa = NULL;
TRACE("Enumerating Shell Service Object GUIDs...\n");
if (RegOpenKeyW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ShellServiceObjectDelayLoad",
&hkey))
{
ERR("RegOpenKeyW failed.\n");
return HRESULT_FROM_WIN32(GetLastError());
}
hdpa = DPA_Create(5);
/* Enumerate */
do
{
DWORD name_len = MAX_PATH;
DWORD value_len = sizeof(value); /* byte count! */
ret = RegEnumValueW(hkey, count, name, &name_len, 0, &type, (LPBYTE) &value, &value_len);
if (ret)
break;
if (type != REG_SZ)
{
WARN("Value type was not REG_SZ.\n");
continue;
}
hr = CLSIDFromString(value, &clsid);
if (FAILED_UNEXPECTEDLY(hr))
{
ERR("CLSIDFromString failed %08x.\n", hr);
goto cleanup;
}
hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IOleCommandTarget, &pOct));
if (FAILED_UNEXPECTEDLY(hr))
{
ERR("CoCreateInstance failed %08x.\n", hr);
goto cleanup;
}
DPA_AppendPtr(hdpa, pOct);
count++;
}
while (1);
if (ret != ERROR_NO_MORE_ITEMS)
{
ERR("RegEnumValueW failed %08x.\n", ret);
hr = HRESULT_FROM_WIN32(GetLastError());
goto cleanup;
}
/* Initialize */
DPA_EnumCallback(hdpa, InitializeAllCallback, &hr);
if (FAILED_UNEXPECTEDLY(hr))
goto cleanup;
RegCloseKey(hkey);
*phdpa = hdpa;
return count > 0 ? S_OK : S_FALSE;
cleanup:
RegCloseKey(hkey);
*phdpa = NULL;
ShutdownShellServices(hdpa);
return hr;
}
HRESULT ShutdownShellServices(HDPA hdpa)
{
DPA_EnumCallback(hdpa, ShutdownAllCallback, NULL);
DPA_EnumCallback(hdpa, DeleteAllEnumCallback, NULL);
DPA_Destroy(hdpa);
return S_OK;
}