Add elevation capacity for wingup if plugins are installed in %PROGRAMDATA%

While plugins are in %PROGRAMDATA%, we need admin's rights to modify them. This PR detects the plugins installation in %PROGRAMDATA%, then launch wingup with UAC.
This commit is contained in:
Don HO 2018-11-24 16:26:24 +01:00
parent 116f400753
commit 61402a354f
5 changed files with 13 additions and 7 deletions

View File

@ -30,19 +30,19 @@
#include "Processus.h"
void Process::run() const
void Process::run(bool isElevationRequired) const
{
const TCHAR *opVerb = TEXT("open");
const TCHAR *opVerb = isElevationRequired ? TEXT("runas") : TEXT("open");
::ShellExecute(NULL, opVerb, _command.c_str(), _args.c_str(), _curDir.c_str(), SW_SHOWNORMAL);
}
unsigned long Process::runSync() const
unsigned long Process::runSync(bool isElevationRequired) const
{
SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = TEXT("open");
ShExecInfo.lpVerb = isElevationRequired ? TEXT("runas") : TEXT("open");
ShExecInfo.lpFile = _command.c_str();
ShExecInfo.lpParameters = _args.c_str();
ShExecInfo.lpDirectory = _curDir.c_str();

View File

@ -39,8 +39,8 @@ public:
Process(const TCHAR *cmd, const TCHAR *args, const TCHAR *cDir)
:_command(cmd), _args(args), _curDir(cDir){}
void run() const;
unsigned long runSync() const;
void run(bool isElevationRequired = false) const;
unsigned long runSync(bool isElevationRequired = false) const;
protected:
generic_string _command;

View File

@ -1854,7 +1854,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
if (!updaterFullPath.empty())
{
Process updater(updaterFullPath.c_str(), pNppParam->getWingupParams().c_str(), pNppParam->getWingupDir().c_str());
updater.run();
updater.run(pNppParam->shouldDoUAC());
}
}
return TRUE;

View File

@ -1052,6 +1052,9 @@ bool NppParameters::load()
nppPluginRootParent = _pluginRootDir;
PathAppend(_pluginRootDir, TEXT("plugins"));
// For PluginAdmin to launch the wingup with UAC
setElevationRequired(true);
}
if (!PathFileExists(nppPluginRootParent.c_str()))

View File

@ -1751,14 +1751,17 @@ private:
generic_string _wingupFullPath;
generic_string _wingupParams;
generic_string _wingupDir;
bool _isElevationRequired = false;
public:
generic_string getWingupFullPath() const { return _wingupFullPath; };
generic_string getWingupParams() const { return _wingupParams; };
generic_string getWingupDir() const { return _wingupDir; };
bool shouldDoUAC() const { return _isElevationRequired; };
void setWingupFullPath(const generic_string& val2set) { _wingupFullPath = val2set; };
void setWingupParams(const generic_string& val2set) { _wingupParams = val2set; };
void setWingupDir(const generic_string& val2set) { _wingupDir = val2set; };
void setElevationRequired(bool val2set) { _isElevationRequired = val2set; };
private:
void getLangKeywordsFromXmlTree();