`
newweapon
  • 浏览: 25015 次
  • 性别: Icon_minigender_1
  • 来自: hefei
最近访客 更多访客>>
社区版块
存档分类
最新评论

Elevate through ShellExecute

阅读更多
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;
}

Maarten

Published Monday, September 25, 2006 11:18 PM by VistaCompatTeam

From: http://blogs.msdn.com/vistacompatteam/archive/2006/09/25/771232.aspx
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics