4 * Copyright 2014 - David Quintana
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.
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.
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
23 static int CALLBACK
InitializeAllCallback(void* pItem
, void* pData
)
25 IOleCommandTarget
* pOct
= reinterpret_cast<IOleCommandTarget
*>(pItem
);
26 HRESULT
* phr
= reinterpret_cast<HRESULT
*>(pData
);
27 TRACE("Initializing SSO %p\n", pOct
);
28 *phr
= pOct
->Exec(&CGID_ShellServiceObject
, OLECMDID_NEW
, OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
29 return SUCCEEDED(*phr
);
32 static int CALLBACK
ShutdownAllCallback(void* pItem
, void* pData
)
34 IOleCommandTarget
* pOct
= reinterpret_cast<IOleCommandTarget
*>(pItem
);
35 TRACE("Shutting down SSO %p\n", pOct
);
36 pOct
->Exec(&CGID_ShellServiceObject
, OLECMDID_SAVE
, OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
40 static int CALLBACK
DeleteAllEnumCallback(void* pItem
, void* pData
)
42 IOleCommandTarget
* pOct
= reinterpret_cast<IOleCommandTarget
*>(pItem
);
43 TRACE("Releasing SSO %p\n", pOct
);
48 HRESULT
InitShellServices(HDPA
* phdpa
)
50 IOleCommandTarget
* pOct
;
54 WCHAR value
[MAX_PATH
];
63 TRACE("Enumerating Shell Service Object GUIDs...\n");
65 if (RegOpenKeyW(HKEY_LOCAL_MACHINE
,
66 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ShellServiceObjectDelayLoad",
69 ERR("RegOpenKeyW failed.\n");
70 return HRESULT_FROM_WIN32(GetLastError());
78 DWORD name_len
= MAX_PATH
;
79 DWORD value_len
= sizeof(value
); /* byte count! */
81 ret
= RegEnumValueW(hkey
, count
, name
, &name_len
, 0, &type
, (LPBYTE
) &value
, &value_len
);
87 WARN("Value type was not REG_SZ.\n");
91 hr
= CLSIDFromString(value
, &clsid
);
92 if (FAILED_UNEXPECTEDLY(hr
))
94 ERR("CLSIDFromString failed %08x.\n", hr
);
98 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
, IID_PPV_ARG(IOleCommandTarget
, &pOct
));
99 if (FAILED_UNEXPECTEDLY(hr
))
101 ERR("CoCreateInstance failed %08x.\n", hr
);
105 DPA_AppendPtr(hdpa
, pOct
);
111 if (ret
!= ERROR_NO_MORE_ITEMS
)
113 ERR("RegEnumValueW failed %08x.\n", ret
);
114 hr
= HRESULT_FROM_WIN32(GetLastError());
121 DPA_EnumCallback(hdpa
, InitializeAllCallback
, &hr
);
122 if (FAILED_UNEXPECTEDLY(hr
))
126 return count
> 0 ? S_OK
: S_FALSE
;
130 ShutdownShellServices(hdpa
);
134 HRESULT
ShutdownShellServices(HDPA hdpa
)
136 DPA_EnumCallback(hdpa
, ShutdownAllCallback
, NULL
);
137 DPA_EnumCallback(hdpa
, DeleteAllEnumCallback
, NULL
);