Request administrator privileges (Win & Mac atleast)


#1

Im building a web installer, and so far got it to work on mac using applescript, but on windows.. seems like a whole deal, is there any cross platform resource i could use to gain access on both platforms.. if not, could this be considered as a feature request?

thanks in advance


#2

There has always been a Process::raisePrivilege() method, but I think it's only implemented on linux currently.


#3

on Windows there is a linker option, UAC Execution Level "require Administrator".

Jules: This should be an option in Introjucer, if someone wants to create a setup application. (For example plugin-installer)

 


#4

On Windows, you probably have to restart the process with admin rights. You can do it like this:

 

static bool elevateToAdminRights(String commandLineArgs)
{
    char szPath[MAX_PATH];
    if (GetModuleFileName(NULL, szPath, ARRAYSIZE(szPath)))
    {
        // Re-launch ourselves with admin rights
        SHELLEXECUTEINFO sei = { sizeof(sei) };
        sei.lpVerb = "runas";
        sei.lpFile = szPath;
        sei.hwnd = NULL;
        sei.nShow = SW_NORMAL;
        sei.lpParameters = commandLineArgs.getCharPointer();
        if (!ShellExecuteEx(&sei))
        {
            DWORD dwError = GetLastError();
            if (dwError == ERROR_CANCELLED)
            {
                // User refused to allow privileges elevation.
                return false;
            }
        }
        else
        {
            _exit(1);
        }
    }
    return false;
}

 


#5

hey thanks for the input !! myhrman i tried your code and it locks quite brutally, can you show how you are using it? thanks in advance man really appreciate


#6

Nevermind guys !!! the linker preference thing on Visual Studio is way easier.. but it wil be rewritten every time i save the project with the introjucer !!! please help jules !!


#7

Busy right now but if you could give me a mod for the introjucer, it's something I'd be happy to add!