/* Toolbar buttons */
-TBBUTTON Buttons [NUM_BUTTONS] =
+static const TBBUTTON Buttons [] =
{ /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
{TBICON_PROP, ID_PROP, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0}, /* properties */
{TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh */
{
HMENU hMainMenu;
DWORD Flags, State;
+ UINT i;
/* get handle to menu */
hMainMenu = GetMenu(Info->hMainWnd);
/* set all to greyed */
- EnableMenuItem(hMainMenu, ID_START, MF_GRAYED);
- EnableMenuItem(hMainMenu, ID_STOP, MF_GRAYED);
- EnableMenuItem(hMainMenu, ID_PAUSE, MF_GRAYED);
- EnableMenuItem(hMainMenu, ID_RESUME, MF_GRAYED);
- EnableMenuItem(hMainMenu, ID_RESTART, MF_GRAYED);
-
- EnableMenuItem(Info->hShortcutMenu, ID_START, MF_GRAYED);
- EnableMenuItem(Info->hShortcutMenu, ID_STOP, MF_GRAYED);
- EnableMenuItem(Info->hShortcutMenu, ID_PAUSE, MF_GRAYED);
- EnableMenuItem(Info->hShortcutMenu, ID_RESUME, MF_GRAYED);
- EnableMenuItem(Info->hShortcutMenu, ID_RESTART, MF_GRAYED);
-
- SendMessage(Info->hTool, TB_SETSTATE, ID_START,
- (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
- SendMessage(Info->hTool, TB_SETSTATE, ID_STOP,
- (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
- SendMessage(Info->hTool, TB_SETSTATE, ID_PAUSE,
- (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
- SendMessage(Info->hTool, TB_SETSTATE, ID_RESTART,
- (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
+ for (i = ID_START; i <= ID_RESTART; i++)
+ {
+ EnableMenuItem(hMainMenu, i, MF_GRAYED);
+ EnableMenuItem(Info->hShortcutMenu, ID_START, MF_GRAYED);
+ SendMessage(Info->hTool, TB_SETSTATE, i,
+ (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
+ }
if (Info->SelectedItem != NO_ITEM_SELECTED)
{
static BOOL
pCreateToolbar(PMAIN_WND_INFO Info)
{
- INT NumButtons = sizeof(Buttons) / sizeof(Buttons[0]);
+ INT numButtons = sizeof(Buttons) / sizeof(Buttons[0]);
Info->hTool = CreateWindowEx(0,
TOOLBARCLASSNAME,
SendMessage(Info->hTool,
TB_ADDBUTTONS,
- NumButtons,
+ numButtons,
(LPARAM)Buttons);
return TRUE;
(void)ListView_SetImageList(Info->hListView,
hLarge,
LVSIL_NORMAL);
-
}
if(Info->hStatus == NULL)
return FALSE;
-
SendMessage(Info->hStatus,
SB_SETPARTS,
sizeof(StatWidths) / sizeof(INT),
ListViewSelectionChanged(PMAIN_WND_INFO Info,
LPNMLISTVIEW pnmv)
{
-
HMENU hMainMenu;
/* get handle to menu */
}
-static VOID
+static BOOL
InitMainWnd(PMAIN_WND_INFO Info)
{
if (!pCreateToolbar(Info))
+ {
DisplayString(_T("error creating toolbar"));
+ return FALSE;
+ }
if (!CreateListView(Info))
{
DisplayString(_T("error creating list view"));
- return;
+ return FALSE;
}
if (!CreateStatusBar(Info))
MAKEINTRESOURCE(IDR_POPUP));
Info->hShortcutMenu = GetSubMenu(Info->hShortcutMenu,
0);
+
+ return TRUE;
}
GWLP_USERDATA,
(LONG_PTR)Info);
- InitMainWnd(Info);
+ if (!InitMainWnd(Info))
+ return -1;
/* Show the window */
ShowWindow(hwnd,
case WM_CLOSE:
{
- /* Free service array */
HeapFree(ProcessHeap,
0,
- Info->pServiceStatus);
+ Info->pAllServices);
DestroyMenu(Info->hShortcutMenu);
DestroyWindow(hwnd);
case WM_DESTROY:
{
- //DestroyMainWnd(Info);
-
HeapFree(ProcessHeap,
0,
Info);
GWLP_USERDATA,
0);
- /* Break the message queue loop */
PostQuitMessage(0);
}
break;
}
break;
}
+
return Ret;
}
UnregisterClass(szMainWndClass,
hInstance);
}
-
#define NO_ITEM_SELECTED -1
#define MAX_KEY_LENGTH 256
-#define NUM_BUTTONS 11
-#define PROGRESSRANGE 8
-
typedef struct _MAIN_WND_INFO
{
HMENU hShortcutMenu;
int nCmdShow;
- ENUM_SERVICE_STATUS_PROCESS *pServiceStatus; /* Stores the complete services array */
+ ENUM_SERVICE_STATUS_PROCESS *pAllServices;
ENUM_SERVICE_STATUS_PROCESS *CurrentService; /* Stores the current selected service */
INT SelectedItem;/* selection number in the list view */
LPTSTR GetDescription(LPTSTR);
LPTSTR GetExecutablePath(PMAIN_WND_INFO Info);
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
-DWORD GetServiceList(PMAIN_WND_INFO Info);
+//DWORD GetServiceList(PMAIN_WND_INFO Info);
/* propsheet.c */
LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info);
INT AllocAndLoadString(OUT LPTSTR *lpTarget,
IN HINSTANCE hInst,
IN UINT uID);
-
DWORD LoadAndFormatString(IN HINSTANCE hInstance,
IN UINT uID,
OUT LPTSTR *lpTarget,
...);
-
BOOL StatusBarLoadAndFormatString(IN HWND hStatusBar,
IN INT PartId,
IN HINSTANCE hInstance,
IN UINT uID,
...);
-
BOOL StatusBarLoadString(IN HWND hStatusBar,
IN INT PartId,
IN HINSTANCE hInstance,
IN UINT uID);
-
INT GetTextFromEdit(OUT LPTSTR lpString,
IN HWND hDlg,
IN UINT Res);
-
VOID GetError(VOID);
-
VOID DisplayString(PTCHAR);
-
HIMAGELIST InitImageList(UINT NumButtons,
UINT StartResource,
UINT Width,
UINT Height);
-
#endif /* __SERVMAN_PRECOMP_H */
}
-
/* get vendor of service binary */
LPTSTR
GetExecutablePath(PMAIN_WND_INFO Info)
}
+static BOOL
+GetServiceList(PMAIN_WND_INFO Info,
+ DWORD *NumServices)
+{
+ SC_HANDLE ScHandle;
+ BOOL bRet = FALSE;
+
+ DWORD BytesNeeded = 0;
+ DWORD ResumeHandle = 0;
+
+ *NumServices = 0;
+
+ ScHandle = OpenSCManager(NULL,
+ NULL,
+ SC_MANAGER_ENUMERATE_SERVICE);
+ if (ScHandle != INVALID_HANDLE_VALUE)
+ {
+ if (!EnumServicesStatusEx(ScHandle,
+ SC_ENUM_PROCESS_INFO,
+ SERVICE_WIN32,
+ SERVICE_STATE_ALL,
+ NULL,
+ 0,
+ &BytesNeeded,
+ NumServices,
+ &ResumeHandle,
+ 0))
+ {
+ /* Call function again if required size was returned */
+ if (GetLastError() == ERROR_MORE_DATA)
+ {
+ /* reserve memory for service info array */
+ Info->pAllServices = (ENUM_SERVICE_STATUS_PROCESS *) HeapAlloc(ProcessHeap,
+ 0,
+ BytesNeeded);
+ if (Info->pAllServices)
+ {
+ /* fill array with service info */
+ if (EnumServicesStatusEx(ScHandle,
+ SC_ENUM_PROCESS_INFO,
+ SERVICE_WIN32,
+ SERVICE_STATE_ALL,
+ (LPBYTE)Info->pAllServices,
+ BytesNeeded,
+ &BytesNeeded,
+ NumServices,
+ &ResumeHandle,
+ 0))
+ {
+ bRet = TRUE;
+ }
+ }
+ }
+ }
+ }
+
+ if (ScHandle)
+ CloseServiceHandle(ScHandle);
+
+ if (!bRet)
+ {
+ HeapFree(ProcessHeap,
+ 0,
+ Info->pAllServices);
+ }
+
+ return bRet;
+}
+
+
BOOL
RefreshServiceList(PMAIN_WND_INFO Info)
{
+ ENUM_SERVICE_STATUS_PROCESS *pService;
LVITEM lvItem;
TCHAR szNumServices[32];
TCHAR szStatus[64];
- DWORD NumServices = 0;
+ DWORD NumServices;
DWORD Index;
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
(void)ListView_DeleteAllItems(Info->hListView);
- NumServices = GetServiceList(Info);
-
- if (NumServices)
+ if (GetServiceList(Info, &NumServices))
{
TCHAR buf[300]; /* buffer to hold key path */
INT NumListedServ = 0; /* how many services were listed */
{
HKEY hKey = NULL;
LPTSTR lpDescription = NULL;
- LPTSTR LogOnAs = NULL;
+ LPTSTR lpLogOnAs = NULL;
DWORD StartUp = 0;
DWORD dwValueSize;
+ /* copy the service info over */
+ pService = &Info->pAllServices[Index];
+
/* open the registry key for the service */
_sntprintf(buf,
300,
Path,
- Info->pServiceStatus[Index].lpServiceName);
-
- RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- buf,
+ pService->lpServiceName);
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ buf,
+ 0,
+ KEY_READ,
+ &hKey) != ERROR_SUCCESS)
+ {
+ HeapFree(ProcessHeap,
0,
- KEY_READ,
- &hKey);
-
+ pService);
+ continue;
+ }
/* set the display name */
ZeroMemory(&lvItem, sizeof(LVITEM));
lvItem.mask = LVIF_TEXT | LVIF_PARAM;
- lvItem.pszText = Info->pServiceStatus[Index].lpDisplayName;
+ lvItem.pszText = pService->lpDisplayName;
- /* Set a pointer for each service so we can query it later.
- * Not all services are added to the list, so we can't query
- * the item number as they become out of sync with the array */
- lvItem.lParam = (LPARAM)&Info->pServiceStatus[Index];
+ /* Add the service pointer */
+ lvItem.lParam = (LPARAM)pService;
- lvItem.iItem = ListView_GetItemCount(Info->hListView);
+ /* add it to the listview */
lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
/* set the description */
- if ((lpDescription = GetDescription(Info->pServiceStatus[Index].lpServiceName)))
+ if ((lpDescription = GetDescription(pService->lpServiceName)))
{
lvItem.pszText = lpDescription;
lvItem.iSubItem = 1;
}
/* set the status */
- if (Info->pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
+ if (pService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
{
LoadString(hInstance,
IDS_SERVICES_STARTED,
NULL,
NULL,
(LPBYTE)&StartUp,
- &dwValueSize))
+ &dwValueSize) == ERROR_SUCCESS)
{
- RegCloseKey(hKey);
- continue;
- }
+ switch (StartUp)
+ {
+ case 2:
+ LoadStringW(hInstance,
+ IDS_SERVICES_AUTO,
+ szStatus,
+ sizeof(szStatus) / sizeof(TCHAR));
+ break;
+ case 3:
+ LoadStringW(hInstance,
+ IDS_SERVICES_MAN,
+ szStatus,
+ sizeof(szStatus) / sizeof(TCHAR));
+ break;
+
+ case 4:
+ LoadStringW(hInstance,
+ IDS_SERVICES_DIS,
+ szStatus,
+ sizeof(szStatus) / sizeof(TCHAR));
+ break;
+ default:
+ szStatus[0] = 0;
+ break;
+ }
- if (StartUp == 0x02)
- {
- LoadString(hInstance,
- IDS_SERVICES_AUTO,
- szStatus,
- sizeof(szStatus) / sizeof(TCHAR));
- lvItem.pszText = szStatus;
- lvItem.iSubItem = 3;
- SendMessage(Info->hListView,
- LVM_SETITEMTEXT,
- lvItem.iItem,
- (LPARAM)&lvItem);
- }
- else if (StartUp == 0x03)
- {
- LoadString(hInstance,
- IDS_SERVICES_MAN,
- szStatus,
- sizeof(szStatus) / sizeof(TCHAR));
- lvItem.pszText = szStatus;
- lvItem.iSubItem = 3;
- SendMessage(Info->hListView,
- LVM_SETITEMTEXT,
- lvItem.iItem,
- (LPARAM)&lvItem);
- }
- else if (StartUp == 0x04)
- {
- LoadString(hInstance,
- IDS_SERVICES_DIS,
- szStatus,
- sizeof(szStatus) / sizeof(TCHAR));
lvItem.pszText = szStatus;
lvItem.iSubItem = 3;
SendMessage(Info->hListView,
NULL,
NULL,
NULL,
- &dwValueSize))
+ &dwValueSize) == ERROR_SUCCESS)
{
- RegCloseKey(hKey);
- continue;
- }
+ lpLogOnAs = HeapAlloc(ProcessHeap,
+ 0,
+ dwValueSize);
+ if (lpLogOnAs != NULL)
+ {
+ if(RegQueryValueEx(hKey,
+ _T("ObjectName"),
+ NULL,
+ NULL,
+ (LPBYTE)lpLogOnAs,
+ &dwValueSize) == ERROR_SUCCESS)
+ {
+ lvItem.pszText = lpLogOnAs;
+ lvItem.iSubItem = 4;
+ SendMessage(Info->hListView,
+ LVM_SETITEMTEXT,
+ lvItem.iItem,
+ (LPARAM)&lvItem);
+ }
+
+ HeapFree(ProcessHeap,
+ 0,
+ lpLogOnAs);
+ }
- LogOnAs = HeapAlloc(ProcessHeap,
- HEAP_ZERO_MEMORY,
- dwValueSize);
- if (LogOnAs == NULL)
- {
RegCloseKey(hKey);
- return FALSE;
}
- if(RegQueryValueEx(hKey,
- _T("ObjectName"),
- NULL,
- NULL,
- (LPBYTE)LogOnAs,
- &dwValueSize))
- {
- HeapFree(ProcessHeap,
- 0,
- LogOnAs);
- RegCloseKey(hKey);
- continue;
- }
-
- lvItem.pszText = LogOnAs;
- lvItem.iSubItem = 4;
- SendMessage(Info->hListView,
- LVM_SETITEMTEXT,
- lvItem.iItem,
- (LPARAM)&lvItem);
-
- HeapFree(ProcessHeap,
- 0,
- LogOnAs);
-
- RegCloseKey(hKey);
-
}
- NumListedServ = ListView_GetItemCount(Info->hListView);
-
/* set the number of listed services in the status bar */
+ NumListedServ = ListView_GetItemCount(Info->hListView);
LoadString(hInstance,
IDS_NUM_SERVICES,
szNumServices,
SendMessage (Info->hListView,
WM_SETREDRAW,
TRUE,
- 0) ;
+ 0);
return TRUE;
}
-
-
-
-
-DWORD
-GetServiceList(PMAIN_WND_INFO Info)
-{
- SC_HANDLE ScHandle;
- BOOL bGotServices = FALSE;
-
- DWORD BytesNeeded = 0;
- DWORD ResumeHandle = 0;
- DWORD NumServices = 0;
-
- ScHandle = OpenSCManager(NULL,
- NULL,
- SC_MANAGER_ENUMERATE_SERVICE);
- if (ScHandle != INVALID_HANDLE_VALUE)
- {
- if (!EnumServicesStatusEx(ScHandle,
- SC_ENUM_PROCESS_INFO,
- SERVICE_WIN32,
- SERVICE_STATE_ALL,
- (LPBYTE)Info->pServiceStatus,
- 0,
- &BytesNeeded,
- &NumServices,
- &ResumeHandle,
- 0))
- {
- /* Call function again if required size was returned */
- if (GetLastError() == ERROR_MORE_DATA)
- {
- /* reserve memory for service info array */
- Info->pServiceStatus = (ENUM_SERVICE_STATUS_PROCESS *)
- HeapAlloc(ProcessHeap,
- 0,
- BytesNeeded);
- if (Info->pServiceStatus == NULL)
- return FALSE;
-
- /* fill array with service info */
- if (EnumServicesStatusEx(ScHandle,
- SC_ENUM_PROCESS_INFO,
- SERVICE_WIN32,
- SERVICE_STATE_ALL,
- (LPBYTE)Info->pServiceStatus,
- BytesNeeded,
- &BytesNeeded,
- &NumServices,
- &ResumeHandle,
- 0))
- {
- bGotServices = TRUE;
- }
- }
- }
- }
-
- if (ScHandle)
- CloseServiceHandle(ScHandle);
-
- if (!bGotServices)
- {
- HeapFree(ProcessHeap,
- 0,
- Info->pServiceStatus);
- }
-
- return NumServices;
-}