关于提升某个进程的权限(ShellExecuteEx)

提升一个进程的权限可以有两种办法

第一、自动提升进程的权限

第二、手动提升进程权限(通过函数提升权限)

             使用函数(ShellExecuteEx)

一直到今天,遇到问题才写测试程序实现:

// testlog.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include
#include
#include

#pragma comment( lib, "Shell32.lib" )

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	
		 允许Vista/Win7下,不同权限进程间发送消息:WM_COPYDATA 
		//typedef BOOL (WINAPI FAR *ChangeWindowMessageFilter_PROC)(UINT,DWORD); 
		//ChangeWindowMessageFilter_PROC m_pfnChangeWindowMessageFilter; 
		//m_pfnChangeWindowMessageFilter = 
		//	(ChangeWindowMessageFilter_PROC)::GetProcAddress (::GetModuleHandle(_T("USER32")),"ChangeWindowMessageFilter"); 
		//if (m_pfnChangeWindowMessageFilter) 
		//{ 
		//	m_pfnChangeWindowMessageFilter(WM_COPYDATA, 1/*Add*/); 
		//} 
  //

		 启动Shell 
		//OSVERSIONINFOEX OSVerInfo; 
		//OSVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 
		//if(!GetVersionEx((OSVERSIONINFO *)&OSVerInfo)) 
		//{ 
		//		OSVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 
		//		GetVersionEx((OSVERSIONINFO *)&OSVerInfo); 
		//} 

		//TCHAR atszVerb[16]; 
		//if(OSVerInfo.dwMajorVersion >= 6) // Vista 以上 
		//{ 
		//		_tcscpy(atszVerb,_T("runas")); 
		//} 
		//else 
		//{ 
		//		_tcscpy(atszVerb,_T("")); 
		//} 

	    SHELLEXECUTEINFO ShExecInfo = {0};
		ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
		ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
		ShExecInfo.hwnd = NULL;
		ShExecInfo.lpVerb = L"runas";
		ShExecInfo.lpFile = L"cmd";
		ShExecInfo.lpParameters = L"";
		ShExecInfo.lpDirectory = NULL;
		ShExecInfo.nShow = SW_SHOW;
		ShExecInfo.hInstApp = NULL;
		ShellExecuteEx(&ShExecInfo);
		WaitForSingleObject(ShExecInfo.hProcess,INFINITE);


	-------------------------------------------------------------------------------------
	//WinExec("C:\\Users\\hevinn\\Desktop\\InstallShield\\edit.exe",SW_SHOW);





	//try
	//{
	//wcout<
以上代码VS2010中测试通过。
运行结果可以明显看到,启动的cmd命令行窗口,的权限是不同的。

你可能感兴趣的:(用心之作,Windows核心编程(书))