3 extern HINSTANCE hInstance
;
7 /* Stores the service array */
8 ENUM_SERVICE_STATUS_PROCESS
*pServiceStatus
= NULL
;
11 /* free service array */
14 HeapFree(GetProcessHeap(), 0, pServiceStatus
);
19 RefreshServiceList(VOID
)
22 TCHAR szNumServices
[32];
24 DWORD NumServices
= 0;
27 NumServices
= GetServiceList();
31 HICON hiconItem
; /* icon for list-view items */
32 HIMAGELIST hSmall
; /* image list for other views */
35 /* Create the icon image lists */
36 hSmall
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
),
37 GetSystemMetrics(SM_CYSMICON
), ILC_MASK
, 1, 1);
39 /* Add an icon to each image list */
40 hiconItem
= LoadImage(hInstance
, MAKEINTRESOURCE(IDI_SM_ICON
), IMAGE_ICON
, 16, 16, 0);
41 ImageList_AddIcon(hSmall
, hiconItem
);
43 ListView_SetImageList(hListView
, hSmall
, LVSIL_SMALL
);
45 /* set the number of services in the status bar */
46 LoadString(hInstance
, IDS_SERVICES_NUM_SERVICES
, szNumServices
, 32);
47 _stprintf(buf
, szNumServices
, NumServices
);
48 SendMessage(hStatus
, SB_SETTEXT
, 0, (LPARAM
)buf
);
51 for (Index
= 0; Index
< NumServices
; Index
++)
54 LPTSTR Description
= NULL
;
56 LPTSTR LogOnAs
= NULL
;
60 /* open the registry key for the service */
61 _stprintf(buf
, _T("System\\CurrentControlSet\\Services\\%s"),
62 pServiceStatus
[Index
].lpServiceName
);
64 if( RegOpenKeyEx(HKEY_LOCAL_MACHINE
,
68 &hKey
) != ERROR_SUCCESS
)
75 /* set the display name */
77 ZeroMemory(&item
, sizeof(LV_ITEM
));
78 item
.mask
= LVIF_TEXT
;
80 item
.pszText
= pServiceStatus
[Index
].lpDisplayName
;
81 item
.iItem
= ListView_GetItemCount(hListView
);
83 item
.iItem
= ListView_InsertItem(hListView
, &item
);
86 /* set the description */
88 ret
= RegQueryValueEx(hKey
,
94 if (ret
!= ERROR_SUCCESS
&& ret
!= ERROR_FILE_NOT_FOUND
)
100 if (ret
!= ERROR_FILE_NOT_FOUND
)
102 Description
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
103 if (Description
== NULL
)
108 if(RegQueryValueEx(hKey
,
115 HeapFree(GetProcessHeap(), 0, Description
);
120 item
.pszText
= Description
;
122 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
124 HeapFree(GetProcessHeap(), 0, Description
);
131 if (pServiceStatus
[Index
].ServiceStatusProcess
.dwCurrentState
== SERVICE_RUNNING
)
133 LoadString(hInstance
, IDS_SERVICES_STATUS_RUNNING
, szStatus
, 128);
134 item
.pszText
= szStatus
;
136 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
142 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
145 /* set the startup type */
147 dwValueSize
= sizeof(DWORD
);
148 if (RegQueryValueEx(hKey
,
161 LoadString(hInstance
, IDS_SERVICES_AUTO
, szStatus
, 128);
162 item
.pszText
= szStatus
;
164 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
166 else if (StartUp
== 0x03)
168 LoadString(hInstance
, IDS_SERVICES_MAN
, szStatus
, 128);
169 item
.pszText
= szStatus
;
171 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
173 else if (StartUp
== 0x04)
175 LoadString(hInstance
, IDS_SERVICES_DIS
, szStatus
, 128);
176 item
.pszText
= szStatus
;
178 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
186 if (RegQueryValueEx(hKey
,
197 LogOnAs
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwValueSize
);
203 if(RegQueryValueEx(hKey
,
210 HeapFree(GetProcessHeap(), 0, LogOnAs
);
215 item
.pszText
= LogOnAs
;
217 SendMessage(hListView
, LVM_SETITEMTEXT
, item
.iItem
, (LPARAM
) &item
);
219 HeapFree(GetProcessHeap(), 0, LogOnAs
);
237 DWORD BytesNeeded
= 0;
238 DWORD ResumeHandle
= 0;
239 DWORD NumServices
= 0;
241 ScHandle
= OpenSCManager(NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
);
242 if (ScHandle
!= INVALID_HANDLE_VALUE
)
244 if (EnumServicesStatusEx(ScHandle
,
245 SC_ENUM_PROCESS_INFO
,
248 (LPBYTE
)pServiceStatus
,
254 /* Call function again if required size was returned */
255 if (GetLastError() == ERROR_MORE_DATA
)
257 /* reserve memory for service info array */
258 pServiceStatus
= (ENUM_SERVICE_STATUS_PROCESS
*) HeapAlloc(GetProcessHeap(), 0, BytesNeeded
);
259 if (pServiceStatus
== NULL
)
262 /* fill array with service info */
263 if (EnumServicesStatusEx(ScHandle
,
264 SC_ENUM_PROCESS_INFO
,
267 (LPBYTE
)pServiceStatus
,
274 HeapFree(GetProcessHeap(), 0, pServiceStatus
);
278 else /* exit on failure */
285 CloseServiceHandle(ScHandle
);
303 //SC_HANDLE hService;
304 //DWORD dwHandle, dwLen;
308 //TCHAR szStrFileInfo[80];
309 //TCHAR FileName[MAX_PATH];
312 //LPSERVICE_FAILURE_ACTIONS pServiceFailureActions = NULL;
313 //LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
316 hService = OpenService(ScHandle,
317 pServiceStatus[Index].lpServiceName,
319 if (hService != INVALID_HANDLE_VALUE)
321 / * check if service is required by the system* /
322 if (!QueryServiceConfig2(hService,
323 SERVICE_CONFIG_FAILURE_ACTIONS,
324 (LPBYTE)pServiceFailureActions,
328 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
330 pServiceFailureActions = (LPSERVICE_FAILURE_ACTIONS)
331 HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
332 if (pServiceFailureActions == NULL)
335 if (!QueryServiceConfig2(hService,
336 SERVICE_CONFIG_FAILURE_ACTIONS,
337 (LPBYTE)pServiceFailureActions,
341 HeapFree(GetProcessHeap(), 0, pServiceFailureActions);
345 else / * exit on failure * /
350 if (pServiceFailureActions->cActions)
352 if (pServiceFailureActions->lpsaActions[0].Type == SC_ACTION_REBOOT)
354 LoadString(hInstance, IDS_SERVICES_YES, szStatus, 128);
355 item.pszText = szStatus;
357 SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
361 if (pServiceFailureActions != NULL)
363 HeapFree(GetProcessHeap(), 0, pServiceFailureActions);
364 pServiceFailureActions = NULL;
367 / * get vendor of service binary * /
369 if (!QueryServiceConfig(hService, pServiceConfig, 0, &BytesNeeded))
371 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
373 pServiceConfig = (LPQUERY_SERVICE_CONFIG)
374 HeapAlloc(GetProcessHeap(), 0, BytesNeeded);
375 if (pServiceConfig == NULL)
378 if (!QueryServiceConfig(hService,
383 HeapFree(GetProcessHeap(), 0, pServiceConfig);
387 else / * exit on failure * /
393 memset(&FileName, 0, MAX_PATH);
394 if (_tcscspn(pServiceConfig->lpBinaryPathName, _T("\"")))
396 _tcsncpy(FileName, pServiceConfig->lpBinaryPathName,
397 _tcscspn(pServiceConfig->lpBinaryPathName, _T(" ")) );
401 _tcscpy(FileName, pServiceConfig->lpBinaryPathName);
404 HeapFree(GetProcessHeap(), 0, pServiceConfig);
405 pServiceConfig = NULL;
407 dwLen = GetFileVersionInfoSize(FileName, &dwHandle);
410 lpData = (TCHAR*) HeapAlloc(GetProcessHeap(), 0, dwLen);
414 if (!GetFileVersionInfo (FileName, dwHandle, dwLen, lpData)) {
415 HeapFree(GetProcessHeap(), 0, lpData);
419 if (VerQueryValue(lpData, _T("\\VarFileInfo\\Translation"), &pvData, (PUINT) &BufLen))
421 wCodePage = LOWORD(*(DWORD*) pvData);
422 wLangID = HIWORD(*(DWORD*) pvData);
423 wsprintf(szStrFileInfo, _T("StringFileInfo\\%04X%04X\\CompanyName"), wCodePage, wLangID);
426 if (VerQueryValue (lpData, szStrFileInfo, (LPVOID) &lpBuffer, (PUINT) &BufLen)) {
427 item.pszText = lpBuffer;
429 SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
431 HeapFree(GetProcessHeap(), 0, lpData);
435 LoadString(hInstance, IDS_SERVICES_UNKNOWN, szStatus, 128);
436 item.pszText = szStatus;
438 SendMessage(hListView, LVM_SETITEMTEXT, item.iItem, (LPARAM) &item);
440 CloseServiceHandle(hService);