Ниже процедура, которая позволяет перегружать права пользователя _без_ выхода из системы. Надеюсь будет полезна.
Данная реализация работает для 3й ахапки (возможно 4й, не проверял).
Для 5ки процедура разработана, пока тестируется (:
X++:
static void ReloadUserRights(Args _args)
{
#WinApi
#AOT
#define.message('Перед обновлением прав буду закрыты все окна. Продолжить?')
Integer item;
container list;
Dictionary dictionary;
Company company;
TreeNode mainMenu;
////////////////////////////////////////////////////////////////////////////////////
// Вспомогательная процедура, возвращает список открытых окон
container getAxChildWindows()
{
container windows;
int counter = 0;
DLL user32 = new DLL('user32');
DLLFunction isVisible = new DLLFunction(user32, 'IsWindowVisible');
hWnd childWnd;
hWnd mdiClient = WinApi::findWindowEx(infolog.hWnd(), 0, 'MDIClient', '');
;
isVisible.returns(ExtTypes::DWord);
isVisible.arg(ExtTypes::DWord);
for (childWnd = WinApi::findWindowEx(mdiClient, 0, '', '');
childWnd;
childWnd = WinApi::findWindowEx(mdiClient, childWnd, '', ''))
{
if (isVisible.call(childWnd) ? true : false)
{
++counter;
windows = conins(windows, counter, childWnd);
}
}
return windows;
}
////////////////////////////////////////////////////////////////////////////////////
;
if (box::yesNo(#message, DialogButton::No, 'Запрос', #message) != DialogButton::Yes)
return ;
//--> получим спиcок дочерних окон и закроем найденые
list = getAxChildWindows();
for(item = 1; item <= conlen(list); item++)
WinAPI::sendMessageEx(conpeek(list, item), #WM_SYSCOMMAND, #SC_CLOSE, 0);
//<-- получим спиcок дочерних окон и закроем найденые
//--> перезагрузим права пользователя
dictionary = new Dictionary();
company = new Company(curExt());
dictionary.reloadSecurity(false, false);
company.reloadRights();
infolog.globalCache().clear(classStr(SysSecurityFormSetup));
if (!domainAccess())
SecurityKeySet::reloadDomainRestrictions();
//<-- перезагрузим права пользователя
//--> откроем главное меню
mainMenu = TreeNode::findNode(strfmt('%1\\MainMenu', #MenusPath));
if (mainMenu != null)
mainMenu.AOTrun();
//<-- откроем главное меню
}