2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
15 #include <afs/param.h>
19 #include "afs_shl_ext.h"
22 #include "shell_ext.h"
25 #include "WINNT\afsreg.h"
27 #include "WINNT\talocale.h"
28 #define STRSAFE_NO_DEPRECATE
34 static char THIS_FILE
[] = __FILE__
;
40 static const IID IID_IShellExt
=
41 { 0xdc515c27, 0x6cac, 0x11d1, { 0xba, 0xe7, 0x0, 0xc0, 0x4f, 0xd1, 0x40, 0xd2 } };
42 static const IID IID_IShellExt2
=
43 { 0xdc515c27, 0x6cac, 0x11d1, { 0xba, 0xe7, 0x0, 0xc0, 0x4f, 0xd1, 0x40, 0xd3 } };
48 static const IID IID_IShellExt
=
49 { 0x5f820ca1, 0x3dde, 0x11db, {0xb2, 0xce, 0x00, 0x15, 0x58, 0x09, 0x2d, 0xb5} };
50 static const IID IID_IShellExt2
=
51 { 0x5f820ca1, 0x3dde, 0x11db, {0xb2, 0xce, 0x00, 0x15, 0x58, 0x09, 0x2d, 0xb6} };
55 /////////////////////////////////////////////////////////////////////////////
58 BEGIN_MESSAGE_MAP(CAfsShlExt
, CWinApp
)
59 //{{AFX_MSG_MAP(CAfsShlExt)
60 // NOTE - the ClassWizard will add and remove mapping macros here.
61 // DO NOT EDIT what you see in these blocks of generated code!
65 /////////////////////////////////////////////////////////////////////////////
66 // CAfsShlExt construction
68 CAfsShlExt::CAfsShlExt()
70 /* Start up sockets */
72 WSAStartup(0x0101, &WSAjunk
);
75 /////////////////////////////////////////////////////////////////////////////
76 // The one and only CAfsShlExt object
80 /////////////////////////////////////////////////////////////////////////////
81 // CAfsShlExt initialization
82 HINSTANCE g_hInstance
;
84 BOOL
CAfsShlExt::InitInstance()
86 // Load our translated resources
87 TaLocale_LoadCorrespondingModuleByName (m_hInstance
, TEXT("afs_shl_ext.dll"));
89 // Register all OLE server (factories) as running. This enables the
90 // OLE libraries to create objects from other applications.
91 COleObjectFactory::RegisterAll();
93 SetHelpPath(m_pszHelpFilePath
);
98 /////////////////////////////////////////////////////////////////////////////
99 // Special entry points required for inproc servers
101 STDAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
* ppv
)
103 AFX_MANAGE_STATE(AfxGetStaticModuleState());
104 return AfxDllGetClassObject(rclsid
, riid
, ppv
);
107 STDAPI
DllCanUnloadNow(void)
109 AFX_MANAGE_STATE(AfxGetStaticModuleState());
112 // This test is correct and we really do want to allow the extension to be loaded and
113 // unloaded as needed. Unfortunately, the extension is being unloaded and never loaded
114 // again which is disconcerting for many folks. For now we will prevent the unloading
115 // until someone has time to figure out how to debug this.
116 // Jeffrey Altman - 2 Oct 2005
118 if (!nCMRefCount
&& !nSERefCount
&& !nICRefCount
&& !nTPRefCount
&& !nXPRefCount
)
124 int WideCharToLocal(LPTSTR pLocal
, LPCWSTR pWide
, DWORD dwChars
)
127 StringCchCopy(pLocal
, dwChars
, pWide
);
130 WideCharToMultiByte( CP_ACP
, 0, pWide
, -1, pLocal
, dwChars
, NULL
, NULL
);
132 return lstrlen(pLocal
);
135 LRESULT
DoRegCLSID(HKEY hKey
,PTCHAR szSubKey
,PTCHAR szData
,PTCHAR szValue
=NULL
)
140 lResult
= RegCreateKeyEx(hKey
, szSubKey
, 0, NULL
,
141 REG_OPTION_NON_VOLATILE
, KEY_WRITE
, NULL
,
143 if(NOERROR
== lResult
)
145 lResult
= RegSetValueEx(thKey
, szValue
, 0, REG_SZ
,
146 (LPBYTE
)szData
, (lstrlen(szData
) + 1)
154 // by exporting DllRegisterServer, you can use regsvr.exe
155 STDAPI
DllRegisterServer(void)
160 TCHAR szSubKey
[MAX_PATH
];
161 TCHAR szCLSID
[MAX_PATH
];
162 TCHAR szModule
[MAX_PATH
];
164 AFX_MANAGE_STATE(AfxGetStaticModuleState());
165 COleObjectFactory::UpdateRegistryAll();
167 StringFromIID(IID_IShellExt
, &pwsz
);
171 StringCbCopy(szCLSID
, sizeof(szCLSID
), pwsz
);
173 WideCharToMultiByte( CP_ACP
, 0,pwsz
, -1, szCLSID
, sizeof(szCLSID
), NULL
, NULL
);
181 [HKEY_CLASSES_ROOT\CLSID\{$CLSID}\InprocServer32]
182 @="Y:\\DEST\\root.client\\usr\\vice\\etc\\afs_shl_ext.dll"
183 "ThreadingModel"="Apartment"
185 HMODULE hModule
=GetModuleHandle(TEXT("afs_shl_ext.dll"));
186 DWORD z
=GetModuleFileName(hModule
,szModule
,sizeof(szModule
));
187 wsprintf(szSubKey
, TEXT("CLSID\\%s\\InprocServer32"),szCLSID
);
188 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szModule
))!=NOERROR
)
191 wsprintf(szSubKey
, TEXT("CLSID\\%s\\InprocServer32"),szCLSID
);
192 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,
193 TEXT("Apartment"),TEXT("ThreadingModel")))!=NOERROR
)
197 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\AFS Client Shell Extension]
198 @="{EA3775F2-28BE-11D3-9C8D-00105A24ED29}"
201 wsprintf(szSubKey
, TEXT("%s\\%s"), STR_REG_PATH
, STR_EXT_TITLE
);
202 if ((lResult
=DoRegCLSID(HKEY_LOCAL_MACHINE
,szSubKey
,szCLSID
))!=NOERROR
)
205 //If running on NT, register the extension as approved.
207 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved]
208 "{$(CLSID)}"="AFS Client Shell Extension"
210 [HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\AFS Client Shell Extension]
215 osvi
.dwOSVersionInfoSize
= sizeof(osvi
);
217 if(VER_PLATFORM_WIN32_NT
== osvi
.dwPlatformId
)
219 wsprintf(szSubKey
, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
220 if ((lResult
=DoRegCLSID(HKEY_LOCAL_MACHINE
,szSubKey
,STR_EXT_TITLE
,szCLSID
))!=NOERROR
)
223 wsprintf(szSubKey
, TEXT("*\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE
);
224 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
226 wsprintf(szSubKey
, TEXT("Folder\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE
);
227 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
229 wsprintf(szSubKey
, TEXT("Directory\\Background\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE
);
230 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
232 wsprintf(szSubKey
, TEXT("LibraryFolder\\background\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE
);
233 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
239 [HKEY_CLASSES_ROOT\Folder\shellex\{00021500-0000-0000-C000-000000000046}]
243 wsprintf(szSubKey
, TEXT("Folder\\shellex\\{00021500-0000-0000-C000-000000000046}"));
244 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
248 /* Below needs to be merged with above */
249 wsprintf(szSubKey
, TEXT("%s\\%s"), STR_REG_PATH
, STR_EXT_TITLE
);
250 lResult
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
,
254 REG_OPTION_NON_VOLATILE
,
260 if(NOERROR
== lResult
)
262 //Create the value string.
263 lResult
= RegSetValueEx( hKey
,
268 (lstrlen(szCLSID
) + 1) * sizeof(TCHAR
));
272 return SELFREG_E_CLASS
;
274 //If running on NT, register the extension as approved.
275 osvi
.dwOSVersionInfoSize
= sizeof(osvi
);
277 if(VER_PLATFORM_WIN32_NT
== osvi
.dwPlatformId
)
279 lstrcpy( szSubKey
, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
281 lResult
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
,
285 REG_OPTION_NON_VOLATILE
,
291 if(NOERROR
== lResult
)
293 TCHAR szData
[MAX_PATH
];
295 //Create the value string.
296 lstrcpy(szData
, STR_EXT_TITLE
);
298 lResult
= RegSetValueEx( hKey
,
303 (lstrlen(szData
) + 1) * sizeof(TCHAR
));
307 return SELFREG_E_CLASS
;
310 StringFromIID(IID_IShellExt2
, &pwsz
);
314 StringCbCopy(szCLSID
, sizeof(szCLSID
), pwsz
);
316 WideCharToMultiByte( CP_ACP
, 0,pwsz
, -1, szCLSID
, sizeof(szCLSID
), NULL
, NULL
);
324 [HKEY_CLASSES_ROOT\CLSID\{$CLSID}\InprocServer32]
325 @="Y:\\DEST\\root.client\\usr\\vice\\etc\\afs_shl_ext.dll"
326 "ThreadingModel"="Apartment"
328 hModule
=GetModuleHandle(TEXT("afs_shl_ext.dll"));
329 z
=GetModuleFileName(hModule
,szModule
,sizeof(szModule
));
330 wsprintf(szSubKey
, TEXT("CLSID\\%s\\InprocServer32"),szCLSID
);
331 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szModule
))!=NOERROR
)
334 wsprintf(szSubKey
, TEXT("CLSID\\%s\\InprocServer32"),szCLSID
);
335 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,
336 TEXT("Apartment"),TEXT("ThreadingModel")))!=NOERROR
)
340 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\AFS Client Shell Extension]
341 @="{EA3775F2-28BE-11D3-9C8D-00105A24ED29}"
344 wsprintf(szSubKey
, TEXT("%s\\%s"), STR_REG_PATH
, STR_EXT_TITLE2
);
345 if ((lResult
=DoRegCLSID(HKEY_LOCAL_MACHINE
,szSubKey
,szCLSID
))!=NOERROR
)
348 //If running on NT, register the extension as approved.
350 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved]
351 "{$(CLSID)}"="AFS Client Shell Extension"
353 [HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\AFS Client Shell Extension]
357 osvi
.dwOSVersionInfoSize
= sizeof(osvi
);
359 if(VER_PLATFORM_WIN32_NT
== osvi
.dwPlatformId
)
361 wsprintf(szSubKey
, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
362 if ((lResult
=DoRegCLSID(HKEY_LOCAL_MACHINE
,szSubKey
,STR_EXT_TITLE2
,szCLSID
))!=NOERROR
)
366 // register property handler
367 wsprintf(szSubKey
, TEXT("*\\shellex\\PropertySheetHandlers\\%s"),STR_EXT_TITLE
);
368 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
370 wsprintf(szSubKey
, TEXT("Drive\\shellex\\PropertySheetHandlers\\%s"),STR_EXT_TITLE
);
371 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
373 wsprintf(szSubKey
, TEXT("Directory\\shellex\\PropertySheetHandlers\\%s"),STR_EXT_TITLE
);
374 if ((lResult
=DoRegCLSID(HKEY_CLASSES_ROOT
,szSubKey
,szCLSID
))!=NOERROR
)
380 //returnValue = RegOpenKeyEx (HKEY_CLASSES_ROOT, keyName, 0, KEY_ALL_ACCESS, ®istryKey);
382 LRESULT
DoValueDelete(HKEY hKey
,PTCHAR pszSubKey
,PTCHAR szValue
=NULL
)
387 lResult
=RegDeleteKey(hKey
, pszSubKey
);
390 lResult
= RegOpenKeyEx( hKey
,
393 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_ALL_ACCESS
,
395 if(NOERROR
== lResult
)
397 lResult
=RegDeleteValue(hKey
, szValue
);
403 STDAPI
DllUnregisterServer(void)
405 TCHAR szSubKey
[MAX_PATH
];
406 TCHAR szCLSID
[MAX_PATH
];
408 AFX_MANAGE_STATE(AfxGetStaticModuleState());
409 COleObjectFactory::UpdateRegistryAll(FALSE
);
410 StringFromIID(IID_IShellExt
, &pwsz
);
414 StringCbCopy(szCLSID
, sizeof(szCLSID
), pwsz
);
416 WideCharToMultiByte( CP_ACP
, 0,pwsz
, -1, szCLSID
, sizeof(szCLSID
), NULL
, NULL
);
422 wsprintf(szSubKey
, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
423 DoValueDelete(HKEY_LOCAL_MACHINE
,szSubKey
,szCLSID
);
424 wsprintf(szSubKey
, TEXT("*\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE
);
425 DoValueDelete(HKEY_CLASSES_ROOT
, szSubKey
);
426 wsprintf(szSubKey
, TEXT("Folder\\shellex\\{00021500-0000-0000-C000-000000000046}"));
427 DoValueDelete(HKEY_CLASSES_ROOT
, szSubKey
);
428 wsprintf(szSubKey
, TEXT("Folder\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE
);
429 DoValueDelete(HKEY_CLASSES_ROOT
, szSubKey
);
430 wsprintf(szSubKey
, TEXT("%s\\%s"), STR_REG_PATH
, STR_EXT_TITLE
);
431 DoValueDelete(HKEY_LOCAL_MACHINE
, szSubKey
);
432 wsprintf(szSubKey
, TEXT("*\\shellex\\PropertySheetHandlers\\%s"),STR_EXT_TITLE
);
433 DoValueDelete(HKEY_CLASSES_ROOT
, szSubKey
);
434 wsprintf(szSubKey
, TEXT("Drive\\shellex\\PropertySheetHandlers\\%s"),STR_EXT_TITLE
);
435 DoValueDelete(HKEY_CLASSES_ROOT
, szSubKey
);
436 wsprintf(szSubKey
, TEXT("Directory\\shellex\\PropertySheetHandlers\\%s"),STR_EXT_TITLE
);
437 DoValueDelete(HKEY_CLASSES_ROOT
, szSubKey
);
439 StringFromIID(IID_IShellExt2
, &pwsz
);
443 StringCbCopy(szCLSID
, sizeof(szCLSID
), pwsz
);
445 WideCharToMultiByte( CP_ACP
, 0,pwsz
, -1, szCLSID
, sizeof(szCLSID
), NULL
, NULL
);
451 wsprintf(szSubKey
, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
452 DoValueDelete(HKEY_LOCAL_MACHINE
,szSubKey
,szCLSID
);