windows服務程式中建立使用者程序

2021-07-08 11:52:24 字數 797 閱讀 3972

最近碰到個問題, 需要在服務中檢測使用者桌面的情況。但是服務程式都是system賬戶下執行, 屬於session0, 不能檢測到使用者桌面的情況。所以就需要另啟乙個使用者程序來獲取這些資訊, 然後傳送給服務。所以就用到了 createprocessasuser來建立使用者程序。

#include #include #include #include #include #pragma comment(lib, "wtsapi32.lib")

#include #pragma comment(lib,"userenv.lib")

using namespace std;

typedef struct _token_linked_token token_linked_token, *ptoken_linked_token;

service_status_handle hservicestatus;

service_status servicestatus;

dword getactivesessionid()

} wtsfreememory(psessioninfo);

return dwsessionid;

}bool serviceexecute(std::wstring wstrcmdline, int32& n32exitresult)

{ ofstream ofile("c:\\logevent.txt");

ofile<<"start excute"<

serviceexecute比createprocess2的實現更加完善, 實際執行中用serviceexecute更好。

用 VC 建立 Windows 服務程式

本文主要介紹了 openscmanager createservice openservice controlservice deleteservice registerservicectrlhandler setservicestatus startservicectrldispatcher等操作...

用 VC 建立 Windows 服務程式

本文主要介紹了 openscmanager createservice openservice controlservice deleteservice registerservicectrlhandler setservicestatus startservicectrldispatcher等操作...

VC 建立Windows服務程式2

本文主要介紹了 openscmanager createservice openservice controlservice deleteservice registerservicectrlhandler setservicestatus startservicectrldispatcher等操作...