Directory Services |
The following program installs an RnR Service class.
#include <winsock2.h> #include <stdio.h> #define BUFFSIZE 200 //{A9033BC1-ECA4-11cf-A054-00AA006C33ED} static GUID SVCID_EXAMPLE_SERVICE = { 0xa9033bc1, 0xeca4, 0x11cf, { 0xa0, 0x54, 0x0, 0xaa, 0x0, 0x6c, 0x33, 0xed } }; HRESULT main(void) { //Data structures for initializing Winsock. WSADATA wsData; WORD wVer = MAKEWORD(2,2); //Data structures for defining and installing a //Winsock service class. WSASERVICECLASSINFO servinfo; WSANSCLASSINFO classinfo[2]; //Values for initializing the data structures. WCHAR wszServiceName[]=L"ExampleService"; WCHAR wszParam1[] =L"MaxConnections"; WCHAR wszParam2[] =L"Timeout"; DWORD dwConn = 64; DWORD dwTmo = 1500; //Miscellaneous variables for status, and so on. DWORD iLen; WCHAR buf[BUFFSIZE]; INT status; //Begin: Init Winsock2 status = WSAStartup(wVer,&wsData); if (status != NO_ERROR) return -1; //Set up the service class data structure. servinfo.lpServiceClassId = &SVCID_EXAMPLE_SERVICE; servinfo.lpszServiceClassName = wszServiceName; servinfo.dwCount = 2; servinfo.lpClassInfos = classinfo; //This service has two items of class-specific data; //set these up in the classinfo array. classinfo[0].lpszName = wszParam1; classinfo[0].dwNameSpace = NS_NTDS; classinfo[0].dwValueType = REG_DWORD; classinfo[0].dwValueSize = sizeof(DWORD); classinfo[0].lpValue = &dwConn; classinfo[1].lpszName = wszParam2; classinfo[1].dwNameSpace = NS_NTDS; classinfo[1].dwValueType = REG_DWORD; classinfo[1].dwValueSize = sizeof(DWORD); classinfo[1].lpValue = &dwTmo; status = WSAInstallServiceClass(&servinfo); if (status != NO_ERROR) printf("Install failed with status %d\n",WSAGetLastError()); //Read the class name back. iLen = BUFFSIZE; //Status = WSAGetServiceClassNameByClassId(&SVCID_EXAMPLE_SERVICE, // buf,&iLen); //if (status != NO_ERROR) { // printf("GetServiceClassName failed with status %d\n", // WSAGetLastError()); //} //Free resources and exit. WSACleanup(); return 0; }