65.9K
CodeProject 正在变化。 阅读更多。
Home

Vista_UAC

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.06/5 (15投票s)

2007年8月21日

viewsIcon

28575

downloadIcon

218

与服务交互。

引言

本文描述了在Vista上以提升权限和非提升权限两种方式与服务进行通信的方法。我使用了命名事件来实现这一点。

背景

由于Vista禁止跨会话发送消息,因此通过服务显示UI是一项艰巨的任务。

使用演示项目

1. 将MessageBox文件夹复制到c:\驱动器

2. 将所有二进制文件复制到一个文件夹中。使用Vista_UAC_Service.exe install安装服务

3. 使用Vista_XP_Compatible.exe测试通过服务创建的UI进程。

代码块应设置为“Formatted”样式,如下所示

//

// Any source code blocks look like this

//

// Giving permissions for all users for the objects has been given at msdn

    "http://msdn2.microsoft.com/en-us/library/ms717798.aspxTCHAR">http://msdn2.microsoft.com/en-us/library/ms717798.aspx

    TCHAR * szSD = TEXT("D:")       // Discretionary ACL

        TEXT("(A;OICI;GA;;;BG)")     // Allow access to 

                                     // built-in guests

        TEXT("(A;OICI;GA;;;AN)")     // Allow access to 

                                     // anonymous logon

        TEXT("(A;OICI;GRGWGX;;;AU)") // Allow 

                                     // read/write/execute 

                                     // to authenticated 

                                     // users

        TEXT("(A;OICI;GA;;;BA)");    // Allow full control 

                                     // to administrators

For getting the session ids in the session 0


WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,0,1,&wsi,&dwNos);

for(int i=0;i<dwNos;i++)

{

if(wsi[i].State == WTSActive)

{

dwSessionId= wsi[i].SessionId;

}

}
Use createprocessasuser for creating the process


bool bRet = ::CreateProcessAsUser( Token, L"c:\\Messagebox\\MessageBox.exe", NULL, NULL, NULL, FALSE,

CREATE_NEW_PROCESS_GROUP | CREATE_UNICODE_ENVIRONMENT|CREATE_NO_WINDOW , pEnv, NULL,

&startupInfo, &processInfo);


© . All rights reserved.