资源描述:
《用服务启动界面程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#ifndef_WIN32_WINNT#define_WIN32_WINNT0x0501#encHf#ifndefWINVER#defineWINVER0x0501#endif#ineludevWindows.h>#include#include#pragmacommentflib,"WtsApi32.lib")//LaunchWithActiceSession()用于在Service中把一个程序以当前活动会话的用户权限运行起来//szExeName可执行程序全路径,同CreatePr
2、ocess()M一个参数//szCmdLine执彳亍程序的命令行,同CreateProcessf)第二个参数//szCurrentDirectory程序运行的当前目录,同CreateProcessf)笫三个参数//bShowWindow该程序是否显示界面//bWait是否等待该程序退出//IpHandle此参数可以返冋进程的HandleDWORDLaunchWithActiceSession(INLPCTSTRszExeName,INLPTSTRszCmdLine=NULL,INLPCTSTRszCurrentDirectory=N
3、ULL,INBOOLbShowWindow=TRUE,INBOOLbWait二FALSE,OUTHANDLE*lpHandle二NULL);DWORDGetLogonSID(INHANDLEhToken,OUTPSID*ppsid){DWORDdwResult=0;DWORDdwlndex=0;DWORDdwLength=0;BOOLbFound=0;PTOKEN_GROUPSptg=NULL;do{if(NULL==ppsid){dwResult=FormatError(ERROR_INVALID_PARAMETER);break
4、;}讦(!::GetTokenlnformation(hToken,TokenGroups,(LPVOID)ptg,0,&dwLength))dwResult=::GetLastError();讦(ERROR」NSUFFICIENT_BUFFER!=dwResult)FormatError(dwResult);break;}dwResult=0;ptg=(PTOKEN_GROUPS)::HeapAlloc(::GetProcessHeap(),HEAP_ZERO_MEMORY;dwLength);if(ptg==NULL){dwRe
5、sult=FormatError(ERROR_NOT_ENOUGH_MEMORY);break;}}if(!::GetTokenlnformation(hToken,TokenGroups,(LPVOID)ptg,dwLength,&dwLength)){dwResult=FormatError(::GetLastError(J);break;}for(dwlndex=0;dwlndexGroupCount;dwlndex++){讦((ptg->Groups[dwlndex].Attributes&SE_GROUP_LO
6、GON」D)==SE_GROUP_LOGON_ID){bFound=TRUE;dwLength=::GetLengthSid(ptg->Groups[dwlndex].Sid);*ppsid=(PSID)::HeapAlloc(::GetProcessHeap(),HEAP_ZERO_MEMORY;dwLength);讦(*ppsid==NULL){dwResult=FormatError(ERROR_NOT_ENOUGH_MEMORY);break;}if(!::CopySid(dwLength,*ppsidzptg->Group
7、s[dwlndex].Sid)){dwResult=FormatError(::GetLastError());::HeapFree(::GetProcessHeap(),0,(LPVOID)*ppsid);break;}break;}}讦(dwResult)break;if(SbFound){dwResult=FormatError(ERROR_FILE_NOT_FOUND);break;}}while(0);if(Ptg)::HeapFreef::GetProcessHeapO,0,(LPVOID)ptg);}returndwR
8、esult;}#defineDESKTOP_ALL(DESKTOP_READOBJECTS
9、DESKTOP_CREATEWINDOW
10、DESKTOP_CREATEMENU
11、DESKTOP_HOOKCONTROL
12、DESKTOPJOU