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 extern HRESULT
InitShellServices(HDPA
* phdpa
);
24 extern HRESULT
ShutdownShellServices(HDPA hdpa
);
26 static int CALLBACK
InitializeAllCallback(void* pItem
, void* pData
)
28 IOleCommandTarget
* pOct
= pItem
;
29 HRESULT
* phr
= pData
;
30 DbgPrint("Initializing SSO %p\n", pOct
);
31 *phr
= IOleCommandTarget_Exec(pOct
, &CGID_ShellServiceObject
, OLECMDID_NEW
, OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
32 return SUCCEEDED(*phr
);
35 static int CALLBACK
ShutdownAllCallback(void* pItem
, void* pData
)
37 IOleCommandTarget
* pOct
= pItem
;
38 DbgPrint("Shutting down SSO %p\n", pOct
);
39 IOleCommandTarget_Exec(pOct
, &CGID_ShellServiceObject
, OLECMDID_SAVE
, OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
43 static int CALLBACK
DeleteAllEnumCallback(void* pItem
, void* pData
)
45 IOleCommandTarget
* pOct
= pItem
;
46 DbgPrint("Releasing SSO %p\n", pOct
);
47 IUnknown_Release(pOct
);
51 HRESULT
InitShellServices(HDPA
* phdpa
)
53 IOleCommandTarget
* pOct
;
57 WCHAR value
[MAX_PATH
];
66 DbgPrint("Enumerating Shell Service Ojbect GUIDs...\n");
68 if (RegOpenKey(HKEY_LOCAL_MACHINE
,
69 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ShellServiceObjectDelayLoad",
72 DbgPrint("ERROR: RegOpenKey failed.\n");
73 return HRESULT_FROM_WIN32(GetLastError());
79 DWORD name_len
= MAX_PATH
;
80 DWORD value_len
= sizeof(value
); /* byte count! */
82 ret
= RegEnumValueW(hkey
, count
, name
, &name_len
, 0, &type
, (LPBYTE
) &value
, &value_len
);
88 DbgPrint("WARNING: Value type was not REG_SZ.\n");
92 hr
= CLSIDFromString(value
, &clsid
);
95 DbgPrint("ERROR: CLSIDFromString failed %08x.\n", hr
);
99 hr
= CoCreateInstance(&clsid
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IOleCommandTarget
, (VOID
**) &pOct
);
102 DbgPrint("ERROR: CoCreateInstance failed %08x.\n", hr
);
106 DPA_AppendPtr(hdpa
, pOct
);
112 if (ret
!= ERROR_NO_MORE_ITEMS
)
114 DbgPrint("ERROR: RegEnumValueW failed %08x.\n", ret
);
115 hr
= HRESULT_FROM_WIN32(GetLastError());
122 DPA_EnumCallback(hdpa
, InitializeAllCallback
, &hr
);
127 return count
> 0 ? S_OK
: S_FALSE
;
131 ShutdownShellServices(hdpa
);
135 HRESULT
ShutdownShellServices(HDPA hdpa
)
137 DPA_EnumCallback(hdpa
, ShutdownAllCallback
, NULL
);
138 DPA_EnumCallback(hdpa
, DeleteAllEnumCallback
, NULL
);