win7 一些UAC相关的问题

来源:互联网 发布:淘宝特卖网qitemei 编辑:程序博客网 时间:2024/05/18 03:02

1.需要管理员权限的程序自启动

程序编译的时候 UAC执行级别选择   asInvoker然后用 ShellExecuteEx 重新启动自己,结束原进程。

2.低权限进程需要向高权限进程发送消息

如果我们想容许一个消息可以发送给较高特权等级的进程,我们可以在较高特权等级的进程中调用ChangeWindowMessageFilter函数,以 MSGFLT_ADD作为参数将消息添加进消息过滤器的白名单。同样的,我们也可以以MSGFLT_REMOVE作为参数将这个消息从白名单中删除。
typedef BOOL (WINAPI*_ChangeWindowMessageFilter)( UINT , DWORD);  BOOL AllowMeesageForVistaAbove(UINT uMessageID, BOOL bAllow)//注册Vista全局消息  {     BOOLbResult = FALSE;     HMODULEhUserMod = NULL;     //vistaand later     hUserMod= LoadLibrary( L"user32.dll" );     if( NULL== hUserMod )     {          return FALSE;     }     _ChangeWindowMessageFilterpChangeWindowMessageFilter =      (_ChangeWindowMessageFilter)GetProcAddress(hUserMod,     "ChangeWindowMessageFilter" );     if( NULL== pChangeWindowMessageFilter )     {       AfxMessageBox(_T("createwindowmessage filter failed"));       returnFALSE;     }     bResult= pChangeWindowMessageFilter( uMessageID, bAllow ?1   : 2 );//MSGFLT_ADD: 1,MSGFLT_REMOVE: 2     if( NULL!= hUserMod )     {        FreeLibrary(hUserMod );     }      returnbResult;  }  

参考:http://blog.csdn.net/chenlycly/article/details/28959293

原创粉丝点击