Elevate through ShellExecute , from Vista Compatibility Team Blog.

We often get the question how to elevate a process through ShellExecute. From the docs it is not immediately clear. The trick is passing in “runas” in the lpVerb.

Here is a snippet to run notepad elevated.

#include “stdafx.h”
#include “windows.h”
#include “shellapi.h”

int _tmain(int argc, _TCHAR* argv[])
{
    SHELLEXECUTEINFO shExecInfo;

    shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);

    shExecInfo.fMask = NULL;
    shExecInfo.hwnd = NULL;
    shExecInfo.lpVerb = L”runas“;
    shExecInfo.lpFile = L”notepad.exe”;
    shExecInfo.lpParameters = NULL;
    shExecInfo.lpDirectory = NULL;
    shExecInfo.nShow = SW_MAXIMIZE;
    shExecInfo.hInstApp = NULL;

    ShellExecuteEx(&shExecInfo);

    return 0;
}

Here is some screenshot:

Popularity: 31% [?]