mirror of
https://github.com/Open-Shell/Open-Shell-Menu.git
synced 2026-04-11 17:37:22 +10:00
StartMenuHelper: Simplify shell extension registration
This commit is contained in:
@@ -453,6 +453,32 @@ static void SaveReportFile( void )
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveShellExtKey(const wchar_t* progID)
|
||||
{
|
||||
static const auto ShellExtName = L"StartMenuExt";
|
||||
auto contextMenuHandlers = std::wstring(progID) + L"\\ShellEx\\ContextMenuHandlers";
|
||||
auto startMenuExt = contextMenuHandlers + L"\\" + ShellExtName;
|
||||
|
||||
HKEY hkey = NULL;
|
||||
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, startMenuExt.c_str(), 0, KEY_READ | KEY_WOW64_64KEY, &hkey) == ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hkey);
|
||||
LogMessage(-1, L"Deleting registry key HKEY_CLASSES_ROOT\\%s", startMenuExt.c_str());
|
||||
auto error = RegCreateKeyEx(HKEY_CLASSES_ROOT, contextMenuHandlers.c_str(), NULL, NULL, REG_OPTION_BACKUP_RESTORE, KEY_WRITE | DELETE | KEY_WOW64_64KEY, NULL, &hkey, NULL);
|
||||
if (error == ERROR_SUCCESS)
|
||||
{
|
||||
error = RegDeleteTree2(hkey, ShellExtName);
|
||||
if (error != ERROR_SUCCESS && error != ERROR_FILE_NOT_FOUND)
|
||||
LogMessage(error, L"Failed to delete registry key HKEY_CLASSES_ROOT\\%s.", startMenuExt.c_str());
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
else if (error != ERROR_FILE_NOT_FOUND)
|
||||
{
|
||||
LogMessage(error, L"Failed to open registry key HKEY_CLASSES_ROOT\\%s for writing.", contextMenuHandlers.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool RemoveRegistryKeys( bool bPin )
|
||||
{
|
||||
HKEY hkey=NULL;
|
||||
@@ -489,40 +515,10 @@ static bool RemoveRegistryKeys( bool bPin )
|
||||
}
|
||||
}
|
||||
|
||||
hkey=NULL;
|
||||
if (bPin)
|
||||
{
|
||||
if (RegOpenKeyEx(HKEY_CLASSES_ROOT,L"Launcher.ImmersiveApplication\\ShellEx\\ContextMenuHandlers\\StartMenuExt",0,KEY_READ|KEY_WOW64_64KEY,&hkey)==ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hkey);
|
||||
LogMessage(-1,L"Deleting registry key HKEY_CLASSES_ROOT\\Launcher.ImmersiveApplication\\ShellEx\\ContextMenuHandlers\\StartMenuExt");
|
||||
error=RegCreateKeyEx(HKEY_CLASSES_ROOT,L"Launcher.ImmersiveApplication\\ShellEx\\ContextMenuHandlers",NULL,NULL,REG_OPTION_BACKUP_RESTORE,KEY_WRITE|DELETE|KEY_WOW64_64KEY,NULL,&hkey,NULL);
|
||||
if (error==ERROR_SUCCESS)
|
||||
{
|
||||
error=RegDeleteTree2(hkey,L"StartMenuExt");
|
||||
if (error!=ERROR_SUCCESS && error!=ERROR_FILE_NOT_FOUND)
|
||||
LogMessage(error,L"Failed to delete registry key HKEY_CLASSES_ROOT\\Launcher.ImmersiveApplication\\ShellEx\\ContextMenuHandlers\\StartMenuExt.");
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
else if (error!=ERROR_FILE_NOT_FOUND)
|
||||
LogMessage(error,L"Failed to open registry key HKEY_CLASSES_ROOT\\Launcher.ImmersiveApplication\\ShellEx\\ContextMenuHandlers for writing.");
|
||||
}
|
||||
|
||||
if (RegOpenKeyEx(HKEY_CLASSES_ROOT,L"Launcher.SystemSettings\\ShellEx\\ContextMenuHandlers\\StartMenuExt",0,KEY_READ|KEY_WOW64_64KEY,&hkey)==ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(hkey);
|
||||
LogMessage(-1,L"Deleting registry key HKEY_CLASSES_ROOT\\Launcher.SystemSettings\\ShellEx\\ContextMenuHandlers\\StartMenuExt");
|
||||
error=RegCreateKeyEx(HKEY_CLASSES_ROOT,L"Launcher.SystemSettings\\ShellEx\\ContextMenuHandlers",NULL,NULL,REG_OPTION_BACKUP_RESTORE,KEY_WRITE|DELETE|KEY_WOW64_64KEY,NULL,&hkey,NULL);
|
||||
if (error==ERROR_SUCCESS)
|
||||
{
|
||||
error=RegDeleteTree2(hkey,L"StartMenuExt");
|
||||
if (error!=ERROR_SUCCESS && error!=ERROR_FILE_NOT_FOUND)
|
||||
LogMessage(error,L"Failed to delete registry key HKEY_CLASSES_ROOT\\Launcher.SystemSettings\\ShellEx\\ContextMenuHandlers\\StartMenuExt.");
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
else if (error!=ERROR_FILE_NOT_FOUND)
|
||||
LogMessage(error,L"Failed to open registry key HKEY_CLASSES_ROOT\\Launcher.SystemSettings\\ShellEx\\ContextMenuHandlers for writing.");
|
||||
}
|
||||
RemoveShellExtKey(L"Launcher.ImmersiveApplication");
|
||||
RemoveShellExtKey(L"Launcher.SystemSettings");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -25,6 +25,8 @@ const CLSID g_ExplorerClsid= {0xECD4FC4D, 0x521C, 0x11D0, {0xB7, 0x92, 0x00, 0xA
|
||||
const CLSID g_EmulationClsid= {0xD3214FBB, 0x3CA1, 0x406A, {0xB3, 0xE8, 0x3E, 0xB7, 0xC3, 0x93, 0xA1, 0x5E}};
|
||||
#define EMULATION_KEY L"TreatAs"
|
||||
|
||||
#define SHELLEXT_NAME L"StartMenuExt"
|
||||
|
||||
static void AdjustPrivileges( void )
|
||||
{
|
||||
HANDLE hToken;
|
||||
@@ -46,6 +48,18 @@ static void AdjustPrivileges( void )
|
||||
}
|
||||
}
|
||||
|
||||
static void AddShellExt(const wchar_t* progID, const LPSECURITY_ATTRIBUTES sa)
|
||||
{
|
||||
HKEY hkey = NULL;
|
||||
|
||||
if (RegCreateKeyEx(HKEY_CLASSES_ROOT, CString(progID) + L"\\ShellEx\\ContextMenuHandlers\\" SHELLEXT_NAME, NULL, NULL, REG_OPTION_BACKUP_RESTORE, KEY_WRITE, sa, &hkey, NULL) == ERROR_SUCCESS)
|
||||
{
|
||||
wchar_t val[] = L"{E595F05F-903F-4318-8B0A-7F633B520D2B}";
|
||||
RegSetValueEx(hkey, NULL, NULL, REG_SZ, (BYTE*)val, sizeof(val));
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
}
|
||||
|
||||
static void AddRegistryKeys( bool bPin )
|
||||
{
|
||||
AdjustPrivileges();
|
||||
@@ -103,21 +117,11 @@ static void AddRegistryKeys( bool bPin )
|
||||
RegSetValueEx(hkey,NULL,NULL,REG_SZ,(BYTE*)val,sizeof(val));
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
hkey=NULL;
|
||||
|
||||
if (bPin)
|
||||
{
|
||||
if (RegCreateKeyEx(HKEY_CLASSES_ROOT,L"Launcher.ImmersiveApplication\\ShellEx\\ContextMenuHandlers\\StartMenuExt",NULL,NULL,REG_OPTION_BACKUP_RESTORE,KEY_WRITE,&sa,&hkey,NULL)==ERROR_SUCCESS)
|
||||
{
|
||||
wchar_t val[]=L"{E595F05F-903F-4318-8B0A-7F633B520D2B}";
|
||||
RegSetValueEx(hkey,NULL,NULL,REG_SZ,(BYTE*)val,sizeof(val));
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
if (RegCreateKeyEx(HKEY_CLASSES_ROOT,L"Launcher.SystemSettings\\ShellEx\\ContextMenuHandlers\\StartMenuExt",NULL,NULL,REG_OPTION_BACKUP_RESTORE,KEY_WRITE,&sa,&hkey,NULL)==ERROR_SUCCESS)
|
||||
{
|
||||
wchar_t val[]=L"{E595F05F-903F-4318-8B0A-7F633B520D2B}";
|
||||
RegSetValueEx(hkey,NULL,NULL,REG_SZ,(BYTE*)val,sizeof(val));
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
AddShellExt(L"Launcher.ImmersiveApplication", &sa);
|
||||
AddShellExt(L"Launcher.SystemSettings", &sa);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,6 +131,16 @@ static void AddRegistryKeys( bool bPin )
|
||||
FreeSid(pAdminSID);
|
||||
}
|
||||
|
||||
static void RemoveShellExt(const wchar_t* progID)
|
||||
{
|
||||
HKEY hkey = NULL;
|
||||
if (RegCreateKeyEx(HKEY_CLASSES_ROOT, CString(progID) + L"\\ShellEx\\ContextMenuHandlers", NULL, NULL, REG_OPTION_BACKUP_RESTORE, KEY_WRITE | DELETE, NULL, &hkey, NULL) == ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteTree(hkey, SHELLEXT_NAME);
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
}
|
||||
|
||||
static void RemoveRegistryKeys( bool bPin )
|
||||
{
|
||||
AdjustPrivileges();
|
||||
@@ -136,19 +150,11 @@ static void RemoveRegistryKeys( bool bPin )
|
||||
RegDeleteTree(hkey,EMULATION_KEY);
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
hkey=NULL;
|
||||
|
||||
if (bPin)
|
||||
{
|
||||
if (RegCreateKeyEx(HKEY_CLASSES_ROOT,L"Launcher.ImmersiveApplication\\ShellEx\\ContextMenuHandlers",NULL,NULL,REG_OPTION_BACKUP_RESTORE,KEY_WRITE|DELETE,NULL,&hkey,NULL)==ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteTree(hkey,L"StartMenuExt");
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
if (RegCreateKeyEx(HKEY_CLASSES_ROOT,L"Launcher.SystemSettings\\ShellEx\\ContextMenuHandlers",NULL,NULL,REG_OPTION_BACKUP_RESTORE,KEY_WRITE|DELETE,NULL,&hkey,NULL)==ERROR_SUCCESS)
|
||||
{
|
||||
RegDeleteTree(hkey,L"StartMenuExt");
|
||||
RegCloseKey(hkey);
|
||||
}
|
||||
RemoveShellExt(L"Launcher.ImmersiveApplication");
|
||||
RemoveShellExt(L"Launcher.SystemSettings");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user