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 #define STRSAFE_NO_DEPRECATE
33 static char THIS_FILE[] = __FILE__;
39 static const IID IID_IShellExt =
40 { 0xdc515c27, 0x6cac, 0x11d1, { 0xba, 0xe7, 0x0, 0xc0, 0x4f, 0xd1, 0x40, 0xd2 } };
45 static const IID IID_IShellExt =
46 { 0x5f820ca1, 0x3dde, 0x11db, {0xb2, 0xce, 0x00, 0x15, 0x58, 0x09, 0x2d, 0xb5} };
50 /////////////////////////////////////////////////////////////////////////////
53 BEGIN_MESSAGE_MAP(CAfsShlExt, CWinApp)
54 //{{AFX_MSG_MAP(CAfsShlExt)
55 // NOTE - the ClassWizard will add and remove mapping macros here.
56 // DO NOT EDIT what you see in these blocks of generated code!
60 /////////////////////////////////////////////////////////////////////////////
61 // CAfsShlExt construction
63 CAfsShlExt::CAfsShlExt()
65 /* Start up sockets */
67 WSAStartup(0x0101, &WSAjunk);
70 /////////////////////////////////////////////////////////////////////////////
71 // The one and only CAfsShlExt object
75 /////////////////////////////////////////////////////////////////////////////
76 // CAfsShlExt initialization
77 HINSTANCE g_hInstance;
79 BOOL CAfsShlExt::InitInstance()
81 extern EXPORTED HINSTANCE TaLocale_LoadCorrespondingModuleByName (HINSTANCE hInstance, LPSTR pszFilename, WORD wSearchPriority = MODULE_PRIORITY_BOOSTED);
83 // Load our translated resources
84 TaLocale_LoadCorrespondingModuleByName (m_hInstance, "afs_shl_ext.dll");
86 // Register all OLE server (factories) as running. This enables the
87 // OLE libraries to create objects from other applications.
88 COleObjectFactory::RegisterAll();
90 SetHelpPath(m_pszHelpFilePath);
95 /////////////////////////////////////////////////////////////////////////////
96 // Special entry points required for inproc servers
98 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
100 AFX_MANAGE_STATE(AfxGetStaticModuleState());
101 return AfxDllGetClassObject(rclsid, riid, ppv);
104 STDAPI DllCanUnloadNow(void)
106 AFX_MANAGE_STATE(AfxGetStaticModuleState());
109 // This test is correct and we really do want to allow the extension to be loaded and
110 // unloaded as needed. Unfortunately, the extension is being unloaded and never loaded
111 // again which is disconcerting for many folks. For now we will prevent the unloading
112 // until someone has time to figure out how to debug this.
113 // Jeffrey Altman - 2 Oct 2005
115 if (!nCMRefCount && !nSERefCount && !nICRefCount && !nTPRefCount && !nXPRefCount)
121 int WideCharToLocal(LPTSTR pLocal, LPCWSTR pWide, DWORD dwChars)
124 StringCchCopy(pLocal, dwChars, pWide);
127 WideCharToMultiByte( CP_ACP, 0, pWide, -1, pLocal, dwChars, NULL, NULL);
129 return lstrlen(pLocal);
132 LRESULT DoRegCLSID(HKEY hKey,PTCHAR szSubKey,PTCHAR szData,PTCHAR szValue=NULL)
137 lResult = RegCreateKeyEx(hKey, szSubKey, 0, NULL,
138 REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
140 if(NOERROR == lResult)
142 lResult = RegSetValueEx(thKey, szValue, 0, REG_SZ,
143 (LPBYTE)szData, (lstrlen(szData) + 1)
151 // by exporting DllRegisterServer, you can use regsvr.exe
152 STDAPI DllRegisterServer(void)
157 TCHAR szSubKey[MAX_PATH];
158 TCHAR szCLSID[MAX_PATH];
159 TCHAR szModule[MAX_PATH];
161 AFX_MANAGE_STATE(AfxGetStaticModuleState());
162 COleObjectFactory::UpdateRegistryAll();
164 StringFromIID(IID_IShellExt, &pwsz);
168 StringCbCopy(szCLSID, sizeof(szCLSID), pwsz);
170 WideCharToMultiByte( CP_ACP, 0,pwsz, -1, szCLSID, sizeof(szCLSID), NULL, NULL);
178 [HKEY_CLASSES_ROOT\CLSID\{$CLSID}\InprocServer32]
179 @="Y:\\DEST\\root.client\\usr\\vice\\etc\\afs_shl_ext.dll"
180 "ThreadingModel"="Apartment"
182 HMODULE hModule=GetModuleHandle(TEXT("afs_shl_ext.dll"));
183 DWORD z=GetModuleFileName(hModule,szModule,sizeof(szModule));
184 wsprintf(szSubKey, TEXT("CLSID\\%s\\InprocServer32"),szCLSID);
185 if ((lResult=DoRegCLSID(HKEY_CLASSES_ROOT,szSubKey,szModule))!=NOERROR)
188 wsprintf(szSubKey, TEXT("CLSID\\%s\\InprocServer32"),szCLSID);
189 if ((lResult=DoRegCLSID(HKEY_CLASSES_ROOT,szSubKey,
190 TEXT("Apartment"),TEXT("ThreadingModel")))!=NOERROR)
194 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\AFS Client Shell Extension]
195 @="{EA3775F2-28BE-11D3-9C8D-00105A24ED29}"
198 wsprintf(szSubKey, TEXT("%s\\%s"), STR_REG_PATH, STR_EXT_TITLE);
199 if ((lResult=DoRegCLSID(HKEY_LOCAL_MACHINE,szSubKey,szCLSID))!=NOERROR)
202 //If running on NT, register the extension as approved.
204 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions\Approved]
205 "{$(CLSID)}"="AFS Client Shell Extension"
207 [HKEY_CLASSES_ROOT\Folder\shellex\ContextMenuHandlers\AFS Client Shell Extension]
212 osvi.dwOSVersionInfoSize = sizeof(osvi);
214 if(VER_PLATFORM_WIN32_NT == osvi.dwPlatformId)
216 wsprintf(szSubKey, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
217 if ((lResult=DoRegCLSID(HKEY_LOCAL_MACHINE,szSubKey,_TEXT(STR_EXT_TITLE),szCLSID))!=NOERROR)
220 wsprintf(szSubKey, TEXT("*\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE);
221 if ((lResult=DoRegCLSID(HKEY_CLASSES_ROOT,szSubKey,szCLSID))!=NOERROR)
223 wsprintf(szSubKey, TEXT("Folder\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE);
224 if ((lResult=DoRegCLSID(HKEY_CLASSES_ROOT,szSubKey,szCLSID))!=NOERROR)
226 wsprintf(szSubKey, TEXT("Directory\\Background\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE);
227 if ((lResult=DoRegCLSID(HKEY_CLASSES_ROOT,szSubKey,szCLSID))!=NOERROR)
229 wsprintf(szSubKey, TEXT("LibraryFolder\\background\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE);
230 if ((lResult=DoRegCLSID(HKEY_CLASSES_ROOT,szSubKey,szCLSID))!=NOERROR)
236 [HKEY_CLASSES_ROOT\Folder\shellex\{00021500-0000-0000-C000-000000000046}]
240 wsprintf(szSubKey, TEXT("Folder\\shellex\\{00021500-0000-0000-C000-000000000046}"));
241 if ((lResult=DoRegCLSID(HKEY_CLASSES_ROOT,szSubKey,szCLSID))!=NOERROR)
245 /* Below needs to be merged with above */
246 wsprintf(szSubKey, TEXT("%s\\%s"), STR_REG_PATH, STR_EXT_TITLE);
247 lResult = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
251 REG_OPTION_NON_VOLATILE,
257 if(NOERROR == lResult)
259 //Create the value string.
260 lResult = RegSetValueEx( hKey,
265 (lstrlen(szCLSID) + 1) * sizeof(TCHAR));
269 return SELFREG_E_CLASS;
271 //If running on NT, register the extension as approved.
272 osvi.dwOSVersionInfoSize = sizeof(osvi);
274 if(VER_PLATFORM_WIN32_NT == osvi.dwPlatformId)
276 lstrcpy( szSubKey, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
278 lResult = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
282 REG_OPTION_NON_VOLATILE,
288 if(NOERROR == lResult)
290 TCHAR szData[MAX_PATH];
292 //Create the value string.
293 lstrcpy(szData, _TEXT(STR_EXT_TITLE));
295 lResult = RegSetValueEx( hKey,
300 (lstrlen(szData) + 1) * sizeof(TCHAR));
304 return SELFREG_E_CLASS;
309 //returnValue = RegOpenKeyEx (HKEY_CLASSES_ROOT, keyName, 0, KEY_ALL_ACCESS, ®istryKey);
311 LRESULT DoValueDelete(HKEY hKey,PTCHAR pszSubKey,PTCHAR szValue=NULL)
316 lResult=RegDeleteKey(hKey, pszSubKey);
319 lResult = RegOpenKeyEx( hKey,
322 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_ALL_ACCESS,
324 if(NOERROR == lResult)
326 lResult=RegDeleteValue(hKey, szValue);
332 STDAPI DllUnregisterServer(void)
334 TCHAR szSubKey[MAX_PATH];
335 TCHAR szCLSID[MAX_PATH];
337 AFX_MANAGE_STATE(AfxGetStaticModuleState());
338 COleObjectFactory::UpdateRegistryAll(FALSE);
339 StringFromIID(IID_IShellExt, &pwsz);
343 StringCbCopy(szCLSID, sizeof(szCLSID), pwsz);
345 WideCharToMultiByte( CP_ACP, 0,pwsz, -1, szCLSID, sizeof(szCLSID), NULL, NULL);
351 wsprintf(szSubKey, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"));
352 DoValueDelete(HKEY_LOCAL_MACHINE,szSubKey,szCLSID);
353 wsprintf(szSubKey, TEXT("*\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE);
354 DoValueDelete(HKEY_CLASSES_ROOT, szSubKey);
355 wsprintf(szSubKey, TEXT("Folder\\shellex\\{00021500-0000-0000-C000-000000000046}"));
356 DoValueDelete(HKEY_CLASSES_ROOT, szSubKey);
357 wsprintf(szSubKey, TEXT("Folder\\shellex\\ContextMenuHandlers\\%s"),STR_EXT_TITLE);
358 DoValueDelete(HKEY_CLASSES_ROOT, szSubKey);
359 wsprintf(szSubKey, TEXT("%s\\%s"), STR_REG_PATH, STR_EXT_TITLE);
360 DoValueDelete(HKEY_LOCAL_MACHINE, szSubKey);