diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index bdeb1b36..42fc2183 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -922,20 +922,23 @@ INT_PTR CDialogManage::CTabSkins::OnCommand(WPARAM wParam, LPARAM lParam) case IDC_MANAGESKINS_EDIT_BUTTON: { - std::wstring command = Rainmeter->GetConfigEditor() + L" \""; - command += Rainmeter->GetSkinPath(); - command += m_SkinName; + std::wstring command = Rainmeter->GetSkinPath() + m_SkinName; command += L"\\"; command += m_FileName; + HANDLE file = CreateFile(command.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + command.insert(0, L" \""); + command.insert(0, Rainmeter->GetConfigEditor()); command += L"\""; - // If the skins are in the program folder start the editor as admin - if (Rainmeter->GetPath() + L"Skins\\" == Rainmeter->GetSkinPath()) + if (file == INVALID_HANDLE_VALUE) { - LSExecuteAsAdmin(NULL, command.c_str(), SW_SHOWNORMAL); + // File is in protected location, so execute as admin + ExecuteCommand(NULL, command.c_str(), SW_SHOWNORMAL, L"runas"); } else { + CloseHandle(file); LSExecute(NULL, command.c_str(), SW_SHOWNORMAL); } } diff --git a/Library/Litestep.cpp b/Library/Litestep.cpp index 9eda88d5..d109164d 100644 --- a/Library/Litestep.cpp +++ b/Library/Litestep.cpp @@ -289,46 +289,46 @@ HRGN BitmapToRegion(HBITMAP hbm, COLORREF clrTransp, COLORREF clrTolerance, int return hRgn; } -HINSTANCE LSExecuteAsAdmin(HWND Owner, LPCTSTR szCommand, int nShowCmd) -{ - BOOL IsInAdminGroup = FALSE; - - SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; - PSID AdministratorsGroup; - // Initialize SID. - if (!AllocateAndInitializeSid( &NtAuthority, - 2, - SECURITY_BUILTIN_DOMAIN_RID, - DOMAIN_ALIAS_RID_ADMINS, - 0, 0, 0, 0, 0, 0, - &AdministratorsGroup)) - { - // Initializing SID Failed. - IsInAdminGroup = FALSE; - } - else - { - // Check whether the token is present in admin group. - if (!CheckTokenMembership( NULL, - AdministratorsGroup, - &IsInAdminGroup )) - { - // Error occurred. - IsInAdminGroup = FALSE; - } - // Free SID and return. - FreeSid(AdministratorsGroup); - } - - if (IsInAdminGroup) - { - return ExecuteCommand(Owner, szCommand, nShowCmd, L"open"); - } - else - { - return ExecuteCommand(Owner, szCommand, nShowCmd, L"runas"); - } -} +//HINSTANCE LSExecuteAsAdmin(HWND Owner, LPCTSTR szCommand, int nShowCmd) +//{ +// BOOL IsInAdminGroup = FALSE; +// +// SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; +// PSID AdministratorsGroup; +// // Initialize SID. +// if (!AllocateAndInitializeSid( &NtAuthority, +// 2, +// SECURITY_BUILTIN_DOMAIN_RID, +// DOMAIN_ALIAS_RID_ADMINS, +// 0, 0, 0, 0, 0, 0, +// &AdministratorsGroup)) +// { +// // Initializing SID Failed. +// IsInAdminGroup = FALSE; +// } +// else +// { +// // Check whether the token is present in admin group. +// if (!CheckTokenMembership( NULL, +// AdministratorsGroup, +// &IsInAdminGroup )) +// { +// // Error occurred. +// IsInAdminGroup = FALSE; +// } +// // Free SID and return. +// FreeSid(AdministratorsGroup); +// } +// +// if (IsInAdminGroup) +// { +// return ExecuteCommand(Owner, szCommand, nShowCmd, L"open"); +// } +// else +// { +// return ExecuteCommand(Owner, szCommand, nShowCmd, L"runas"); +// } +//} HINSTANCE LSExecute(HWND Owner, LPCTSTR szCommand, int nShowCmd) { diff --git a/Library/Litestep.h b/Library/Litestep.h index 9a822521..01c81172 100644 --- a/Library/Litestep.h +++ b/Library/Litestep.h @@ -60,7 +60,7 @@ void LogWithArgs(int nLevel, const WCHAR* format, ... ); // Replacement for Debu void LogError(CError& error); HINSTANCE LSExecute(HWND Owner, LPCTSTR szCommand, int nShowCmd); -HINSTANCE LSExecuteAsAdmin(HWND Owner, LPCTSTR szCommand, int nShowCmd); +//HINSTANCE LSExecuteAsAdmin(HWND Owner, LPCTSTR szCommand, int nShowCmd); HINSTANCE ExecuteCommand(HWND Owner, LPCTSTR szCommand, int nShowCmd, LPCTSTR szVerb); WCHAR* GetString(UINT id); diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 125f05f7..a210de72 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -3621,20 +3621,23 @@ LRESULT CMeterWindow::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam) { if (wParam == ID_CONTEXT_SKINMENU_EDITSKIN) { - std::wstring command = m_Rainmeter->GetConfigEditor() + L" \""; - command += m_SkinPath; - command += m_SkinName; + std::wstring command = m_SkinPath + m_SkinName; command += L"\\"; command += m_SkinIniFile; + HANDLE file = CreateFile(command.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + + command.insert(0, L" \""); + command.insert(0, m_Rainmeter->GetConfigEditor()); command += L"\""; - // If the skins are in the program folder start the editor as admin - if (m_Rainmeter->GetPath() + L"Skins\\" == m_Rainmeter->GetSkinPath()) + if (file == INVALID_HANDLE_VALUE) { - LSExecuteAsAdmin(NULL, command.c_str(), SW_SHOWNORMAL); + // File is in protected location, so execute as admin + ExecuteCommand(NULL, command.c_str(), SW_SHOWNORMAL, L"runas"); } else { + CloseHandle(file); LSExecute(NULL, command.c_str(), SW_SHOWNORMAL); } }