summaryrefslogtreecommitdiff
path: root/shared/privilege.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'shared/privilege.cpp')
-rw-r--r--shared/privilege.cpp37
1 files changed, 9 insertions, 28 deletions
diff --git a/shared/privilege.cpp b/shared/privilege.cpp
index c854ad4e..eaeac866 100644
--- a/shared/privilege.cpp
+++ b/shared/privilege.cpp
@@ -19,10 +19,8 @@ bool Privileges::privilegeIsActive(LPCTSTR privilege) //throw (FileError)
if (!::OpenProcessToken(::GetCurrentProcess(), //__in HANDLE ProcessHandle,
TOKEN_QUERY, //__in DWORD DesiredAccess,
&hToken)) //__out PHANDLE TokenHandle
- {
- const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"");
- throw FileError(errorMessage + wxT("\n\n") + zen::getLastErrorFormatted());
- }
+ throw FileError(_("Error setting privilege:") + " \"" + privilege + "\"" + "\n\n" + getLastErrorFormatted());
+
Loki::ScopeGuard dummy = Loki::MakeGuard(::CloseHandle, hToken);
(void)dummy; //silence warning "unused variable"
@@ -32,10 +30,7 @@ bool Privileges::privilegeIsActive(LPCTSTR privilege) //throw (FileError)
NULL, //__in_opt LPCTSTR lpSystemName,
privilege, //__in LPCTSTR lpName,
&luid )) //__out PLUID lpLuid
- {
- const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"");
- throw FileError(errorMessage + wxT("\n\n") + zen::getLastErrorFormatted());
- }
+ throw FileError(_("Error setting privilege:") + " \"" + privilege + "\"" + "\n\n" + getLastErrorFormatted());
PRIVILEGE_SET priv = {};
priv.PrivilegeCount = 1;
@@ -48,10 +43,7 @@ bool Privileges::privilegeIsActive(LPCTSTR privilege) //throw (FileError)
hToken, //__in HANDLE ClientToken,
&priv, //__inout PPRIVILEGE_SET RequiredPrivileges,
&alreadyGranted)) //__out LPBOOL pfResult
- {
- const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"");
- throw FileError(errorMessage + wxT("\n\n") + zen::getLastErrorFormatted());
- }
+ throw FileError(_("Error setting privilege:") + " \"" + privilege + "\"" + "\n\n" + getLastErrorFormatted());
return alreadyGranted == TRUE;
}
@@ -63,10 +55,8 @@ void Privileges::setPrivilege(LPCTSTR privilege, bool enable) //throw (FileError
if (!::OpenProcessToken(::GetCurrentProcess(), //__in HANDLE ProcessHandle,
TOKEN_ADJUST_PRIVILEGES, //__in DWORD DesiredAccess,
&hToken)) //__out PHANDLE TokenHandle
- {
- const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"");
- throw FileError(errorMessage + wxT("\n\n") + zen::getLastErrorFormatted());
- }
+ throw FileError(_("Error setting privilege:") + " \"" + privilege + "\"" + "\n\n" + getLastErrorFormatted());
+
Loki::ScopeGuard dummy = Loki::MakeGuard(::CloseHandle, hToken);
(void)dummy; //silence warning "unused variable"
@@ -75,10 +65,7 @@ void Privileges::setPrivilege(LPCTSTR privilege, bool enable) //throw (FileError
NULL, //__in_opt LPCTSTR lpSystemName,
privilege, //__in LPCTSTR lpName,
&luid )) //__out PLUID lpLuid
- {
- const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"");
- throw FileError(errorMessage + wxT("\n\n") + zen::getLastErrorFormatted());
- }
+ throw FileError(_("Error setting privilege:") + " \"" + privilege + "\"" + "\n\n" + getLastErrorFormatted());
TOKEN_PRIVILEGES tp = {};
tp.PrivilegeCount = 1;
@@ -92,14 +79,8 @@ void Privileges::setPrivilege(LPCTSTR privilege, bool enable) //throw (FileError
0, //__in DWORD BufferLength,
NULL, //__out_opt PTOKEN_PRIVILEGES PreviousState,
NULL)) //__out_opt PDWORD ReturnLength
- {
- const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"");
- throw FileError(errorMessage + wxT("\n\n") + zen::getLastErrorFormatted());
- }
+ throw FileError(_("Error setting privilege:") + " \"" + privilege + "\"" + "\n\n" + getLastErrorFormatted());
if (::GetLastError() == ERROR_NOT_ALL_ASSIGNED) //check although previous function returned with success!
- {
- const wxString errorMessage = wxString(_("Error setting privilege:")) + wxT(" \"") + privilege + wxT("\"");
- throw FileError(errorMessage + wxT("\n\n") + zen::getLastErrorFormatted());
- }
+ throw FileError(_("Error setting privilege:") + " \"" + privilege + "\"" + "\n\n" + getLastErrorFormatted());
}
bgstack15