Author: gedmurphy
Date: Tue Aug 28 18:49:47 2007
New Revision: 28618
URL:
http://svn.reactos.org/svn/reactos?rev=28618&view=rev
Log:
- don't read the description directly from the registry
- give each property dialog it's own service data instead of relying on the the global
current. This will eventually allow us to have multiple property dialogs open.
Modified:
trunk/reactos/base/applications/mscutils/servman/mainwnd.c
trunk/reactos/base/applications/mscutils/servman/precomp.h
trunk/reactos/base/applications/mscutils/servman/propsheet.c
trunk/reactos/base/applications/mscutils/servman/query.c
trunk/reactos/base/applications/mscutils/servman/reg.c
Modified: trunk/reactos/base/applications/mscutils/servman/mainwnd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/mainwnd.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/mainwnd.c Tue Aug 28 18:49:47 2007
@@ -161,7 +161,7 @@
{
LPTSTR lpDescription;
- lpDescription = GetDescription(Info->pCurrentService->lpServiceName);
+ lpDescription =
GetServiceDescription(Info->pCurrentService->lpServiceName);
item.pszText = lpDescription;
SendMessage(Info->hListView,
Modified: trunk/reactos/base/applications/mscutils/servman/precomp.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/precomp.h (original)
+++ trunk/reactos/base/applications/mscutils/servman/precomp.h Tue Aug 28 18:49:47 2007
@@ -71,13 +71,14 @@
/* query.c */
ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info);
-LPTSTR GetExecutablePath(PMAIN_WND_INFO Info);
+LPQUERY_SERVICE_CONFIG GetServiceConfig(LPTSTR lpServiceName);
+LPTSTR GetServiceDescription(LPTSTR lpServiceName);
+LPTSTR GetExecutablePath(LPTSTR lpServiceName);
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
BOOL UpdateServiceStatus(ENUM_SERVICE_STATUS_PROCESS* pService);
/* reg */
BOOL SetDescription(LPTSTR, LPTSTR);
-LPTSTR GetDescription(LPTSTR);
/* propsheet.c */
LONG APIENTRY OpenPropSheet(PMAIN_WND_INFO Info);
Modified: trunk/reactos/base/applications/mscutils/servman/propsheet.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/propsheet.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/propsheet.c Tue Aug 28 18:49:47 2007
@@ -9,15 +9,22 @@
#include "precomp.h"
+typedef struct _SERVICEPROPSHEET
+{
+ PMAIN_WND_INFO Info;
+ ENUM_SERVICE_STATUS_PROCESS *pService;
+} SERVICEPROPSHEET, *PSERVICEPROPSHEET;
+
+
static VOID
-SetButtonStates(PMAIN_WND_INFO Info,
+SetButtonStates(PSERVICEPROPSHEET dlgInfo,
HWND hwndDlg)
{
HWND hButton;
DWORD Flags, State;
- Flags = Info->pCurrentService->ServiceStatusProcess.dwControlsAccepted;
- State = Info->pCurrentService->ServiceStatusProcess.dwCurrentState;
+ Flags = dlgInfo->pService->ServiceStatusProcess.dwControlsAccepted;
+ State = dlgInfo->pService->ServiceStatusProcess.dwCurrentState;
if (State == SERVICE_STOPPED)
{
@@ -49,56 +56,53 @@
* values and sets it to value of the selected item
*/
static VOID
-SetStartupType(PMAIN_WND_INFO Info,
+SetStartupType(LPTSTR lpServiceName,
HWND hwndDlg)
{
HWND hList;
- HKEY hKey;
- TCHAR buf[25];
- DWORD dwValueSize = 0;
+ LPQUERY_SERVICE_CONFIG pServiceConfig;
+ LPTSTR lpBuf;
DWORD StartUp = 0;
- LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
- TCHAR KeyBuf[300];
-
- /* open the registry key for the service */
- _sntprintf(KeyBuf,
- sizeof(KeyBuf) / sizeof(TCHAR),
- Path,
- Info->pCurrentService->lpServiceName);
-
- RegOpenKeyEx(HKEY_LOCAL_MACHINE,
- KeyBuf,
+ UINT i;
+
+ hList = GetDlgItem(hwndDlg, IDC_START_TYPE);
+
+ for (i = IDS_SERVICES_AUTO; i <= IDS_SERVICES_DIS; i++)
+ {
+ if (AllocAndLoadString(&lpBuf,
+ hInstance,
+ i))
+ {
+ SendMessage(hList,
+ CB_ADDSTRING,
+ 0,
+ (LPARAM)lpBuf);
+ HeapFree(ProcessHeap,
+ 0,
+ lpBuf);
+ }
+ }
+
+ pServiceConfig = GetServiceConfig(lpServiceName);
+
+ if (pServiceConfig)
+ {
+ switch (pServiceConfig->dwStartType)
+ {
+ case SERVICE_AUTO_START: StartUp = 0; break;
+ case SERVICE_DEMAND_START: StartUp = 1; break;
+ case SERVICE_DISABLED: StartUp = 2; break;
+ }
+
+ SendMessage(hList,
+ CB_SETCURSEL,
+ StartUp,
+ 0);
+
+ HeapFree(ProcessHeap,
0,
- KEY_READ,
- &hKey);
-
- hList = GetDlgItem(hwndDlg, IDC_START_TYPE);
-
- LoadString(hInstance, IDS_SERVICES_AUTO, buf, sizeof(buf) / sizeof(TCHAR));
- SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
- LoadString(hInstance, IDS_SERVICES_MAN, buf, sizeof(buf) / sizeof(TCHAR));
- SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
- LoadString(hInstance, IDS_SERVICES_DIS, buf, sizeof(buf) / sizeof(TCHAR));
- SendMessage(hList, CB_ADDSTRING, 0, (LPARAM)buf);
-
- dwValueSize = sizeof(DWORD);
- if (RegQueryValueEx(hKey,
- _T("Start"),
- NULL,
- NULL,
- (LPBYTE)&StartUp,
- &dwValueSize))
- {
- RegCloseKey(hKey);
- return;
- }
-
- if (StartUp == 0x02)
- SendMessage(hList, CB_SETCURSEL, 0, 0);
- else if (StartUp == 0x03)
- SendMessage(hList, CB_SETCURSEL, 1, 0);
- else if (StartUp == 0x04)
- SendMessage(hList, CB_SETCURSEL, 2, 0);
+ pServiceConfig);
+ }
}
@@ -107,28 +111,28 @@
* the relevant service information
*/
static VOID
-GetDlgInfo(PMAIN_WND_INFO Info,
+GetDlgInfo(PSERVICEPROPSHEET dlgInfo,
HWND hwndDlg)
{
+ LPQUERY_SERVICE_CONFIG pServiceConfig;
LPTSTR lpDescription;
- LPTSTR lpPathToExe;
/* set the service name */
SendDlgItemMessage(hwndDlg,
IDC_SERV_NAME,
WM_SETTEXT,
0,
- (LPARAM)Info->pCurrentService->lpServiceName);
+ (LPARAM)dlgInfo->pService->lpServiceName);
/* set the display name */
SendDlgItemMessage(hwndDlg,
IDC_DISP_NAME,
WM_SETTEXT,
0,
- (LPARAM)Info->pCurrentService->lpDisplayName);
+ (LPARAM)dlgInfo->pService->lpDisplayName);
/* set the description */
- if ((lpDescription = GetDescription(Info->pCurrentService->lpServiceName)))
+ if ((lpDescription = GetServiceDescription(dlgInfo->pService->lpServiceName)))
{
SendDlgItemMessage(hwndDlg,
IDC_DESCRIPTION,
@@ -139,29 +143,24 @@
HeapFree(ProcessHeap,
0,
lpDescription);
-
-
- }
-
- /* set the executable path */
- if ((lpPathToExe = GetExecutablePath(Info)))
+ }
+
+ pServiceConfig = GetServiceConfig(dlgInfo->pService->lpServiceName);
+ if (pServiceConfig)
{
SendDlgItemMessage(hwndDlg,
IDC_EXEPATH,
WM_SETTEXT,
0,
- (LPARAM)lpPathToExe);
-
- HeapFree(ProcessHeap,
- 0,
- lpPathToExe);
- }
+ (LPARAM)pServiceConfig->lpBinaryPathName);
+ }
+
/* set startup type */
- SetStartupType(Info, hwndDlg);
+ SetStartupType(dlgInfo->pService->lpServiceName, hwndDlg);
/* set service status */
- if (Info->pCurrentService->ServiceStatusProcess.dwCurrentState ==
SERVICE_RUNNING)
+ if (dlgInfo->pService->ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
{
TCHAR szServiceStatus[32];
@@ -192,7 +191,6 @@
(LPARAM)szServiceStatus);
}
}
-
/*
@@ -205,13 +203,12 @@
WPARAM wParam,
LPARAM lParam)
{
- PMAIN_WND_INFO Info;
+ PSERVICEPROPSHEET dlgInfo;
/* Get the window context */
- Info = (PMAIN_WND_INFO)GetWindowLongPtr(hwndDlg,
- GWLP_USERDATA);
-
- if (Info == NULL && uMsg != WM_INITDIALOG)
+ dlgInfo = (PSERVICEPROPSHEET)GetWindowLongPtr(hwndDlg,
+ GWLP_USERDATA);
+ if (dlgInfo == NULL && uMsg != WM_INITDIALOG)
{
return FALSE;
}
@@ -220,14 +217,14 @@
{
case WM_INITDIALOG:
{
- Info = (PMAIN_WND_INFO)(((LPPROPSHEETPAGE)lParam)->lParam);
- if (Info != NULL)
+ dlgInfo = (PSERVICEPROPSHEET)(((LPPROPSHEETPAGE)lParam)->lParam);
+ if (dlgInfo != NULL)
{
SetWindowLongPtr(hwndDlg,
GWLP_USERDATA,
- (LONG_PTR)Info);
- GetDlgInfo(Info, hwndDlg);
- SetButtonStates(Info, hwndDlg);
+ (LONG_PTR)dlgInfo);
+ GetDlgInfo(dlgInfo, hwndDlg);
+ SetButtonStates(dlgInfo, hwndDlg);
}
}
break;
@@ -236,31 +233,34 @@
switch(LOWORD(wParam))
{
case IDC_START_TYPE:
- /* Enable the 'Apply' button */
- //PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+ if (HIWORD(wParam) == CBN_SELCHANGE)
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
case IDC_START:
- SendMessage(Info->hMainWnd, WM_COMMAND, ID_START, 0);
+ if (DoStart(dlgInfo->Info))
+ {
+ //UpdateServiceStatus(dlgInfo->pService);
+ //ChangeListViewText(dlgInfo, LVSTATUS);
+ //SetMenuAndButtonStates(Info);
+ }
break;
case IDC_STOP:
- SendMessage(Info->hMainWnd, WM_COMMAND, ID_STOP, 0);
+ //SendMessage(Info->hMainWnd, WM_COMMAND, ID_STOP, 0);
break;
case IDC_PAUSE:
- SendMessage(Info->hMainWnd, WM_COMMAND, ID_PAUSE, 0);
+ //SendMessage(Info->hMainWnd, WM_COMMAND, ID_PAUSE, 0);
break;
case IDC_RESUME:
- SendMessage(Info->hMainWnd, WM_COMMAND, ID_RESUME, 0);
+ //SendMessage(Info->hMainWnd, WM_COMMAND, ID_RESUME, 0);
break;
case IDC_START_PARAM:
- /* Enable the 'Apply' button */
- //PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
- break;
-
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+ break;
}
break;
@@ -273,9 +273,8 @@
switch (lpnm->code)
{
- case MCN_SELECT:
- /* Enable the 'Apply' button */
- PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+ case PSN_APPLY:
+ MessageBox(NULL, _T("apply"), NULL, 0);
break;
}
}
@@ -381,7 +380,7 @@
static VOID
InitPropSheetPage(PROPSHEETPAGE *psp,
- PMAIN_WND_INFO Info,
+ PSERVICEPROPSHEET dlgInfo,
WORD idDlg,
DLGPROC DlgProc)
{
@@ -391,7 +390,7 @@
psp->hInstance = hInstance;
psp->pszTemplate = MAKEINTRESOURCE(idDlg);
psp->pfnDlgProc = DlgProc;
- psp->lParam = (LPARAM)Info;
+ psp->lParam = (LPARAM)dlgInfo;
}
@@ -400,6 +399,8 @@
{
PROPSHEETHEADER psh;
PROPSHEETPAGE psp[2];
+ PSERVICEPROPSHEET pServicePropSheet;
+ LONG Ret = 0;
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
@@ -414,11 +415,27 @@
psh.ppsp = psp;
- InitPropSheetPage(&psp[0], Info, IDD_DLG_GENERAL, GeneralPageProc);
- //InitPropSheetPage(&psp[1], Info, IDD_DLG_GENERAL, LogonPageProc);
- //InitPropSheetPage(&psp[2], Info, IDD_DLG_GENERAL, RecoveryPageProc);
- InitPropSheetPage(&psp[1], Info, IDD_DLG_DEPEND, DependanciesPageProc);
-
- return (LONG)(PropertySheet(&psh) != -1);
-}
-
+ pServicePropSheet = HeapAlloc(ProcessHeap,
+ 0,
+ sizeof(*pServicePropSheet));
+ if (pServicePropSheet)
+ {
+ /* save current service, as it could change while the dialog is open */
+ pServicePropSheet->pService = Info->pCurrentService;
+ pServicePropSheet->Info = Info;
+
+ InitPropSheetPage(&psp[0], pServicePropSheet, IDD_DLG_GENERAL,
GeneralPageProc);
+ //InitPropSheetPage(&psp[1], Info, IDD_DLG_GENERAL, LogonPageProc);
+ //InitPropSheetPage(&psp[2], Info, IDD_DLG_GENERAL, RecoveryPageProc);
+ InitPropSheetPage(&psp[1], pServicePropSheet, IDD_DLG_DEPEND,
DependanciesPageProc);
+
+ Ret = (LONG)(PropertySheet(&psh) != -1);
+
+ HeapFree(ProcessHeap,
+ 0,
+ pServicePropSheet);
+ }
+
+ return Ret;
+}
+
Modified: trunk/reactos/base/applications/mscutils/servman/query.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/query.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/query.c Tue Aug 28 18:49:47 2007
@@ -27,29 +27,25 @@
}
-/* get vendor of service binary */
-LPTSTR
-GetExecutablePath(PMAIN_WND_INFO Info)
+LPQUERY_SERVICE_CONFIG
+GetServiceConfig(LPTSTR lpServiceName)
{
SC_HANDLE hSCManager = NULL;
SC_HANDLE hSc = NULL;
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
DWORD BytesNeeded = 0;
- LPTSTR lpExePath = NULL;
-
- /* open handle to the SCM */
+
hSCManager = OpenSCManager(NULL,
NULL,
SC_MANAGER_ENUMERATE_SERVICE);
if (hSCManager == NULL)
{
GetError();
- return FALSE;
- }
-
- /* get a handle to the service requested for starting */
+ return NULL;
+ }
+
hSc = OpenService(hSCManager,
- Info->pCurrentService->lpServiceName,
+ lpServiceName,
SERVICE_QUERY_CONFIG);
if (hSc == NULL)
{
@@ -70,32 +66,101 @@
if (pServiceConfig == NULL)
goto cleanup;
- if (QueryServiceConfig(hSc,
- pServiceConfig,
- BytesNeeded,
- &BytesNeeded))
- {
- lpExePath = HeapAlloc(ProcessHeap,
- 0,
- (_tcslen(pServiceConfig->lpBinaryPathName) +1 )
* sizeof(TCHAR));
-
- _tcscpy(lpExePath, pServiceConfig->lpBinaryPathName);
+ if (!QueryServiceConfig(hSc,
+ pServiceConfig,
+ BytesNeeded,
+ &BytesNeeded))
+ {
+ HeapFree(ProcessHeap,
+ 0,
+ pServiceConfig);
+
+ pServiceConfig = NULL;
}
}
}
cleanup:
- if (pServiceConfig)
- HeapFree(ProcessHeap,
- 0,
- pServiceConfig);
if (hSCManager != NULL)
CloseServiceHandle(hSCManager);
if (hSc != NULL)
CloseServiceHandle(hSc);
- return lpExePath;
-}
+ return pServiceConfig;
+}
+
+
+LPTSTR
+GetServiceDescription(LPTSTR lpServiceName)
+{
+ SC_HANDLE hSCManager = NULL;
+ SC_HANDLE hSc = NULL;
+ SERVICE_DESCRIPTION *pServiceDescription = NULL;
+ LPTSTR lpDescription = NULL;
+ DWORD BytesNeeded = 0;
+
+ hSCManager = OpenSCManager(NULL,
+ NULL,
+ SC_MANAGER_ENUMERATE_SERVICE);
+ if (hSCManager == NULL)
+ {
+ GetError();
+ return NULL;
+ }
+
+ hSc = OpenService(hSCManager,
+ lpServiceName,
+ SERVICE_QUERY_CONFIG);
+ if (hSc)
+ {
+ if (!QueryServiceConfig2(hSc,
+ SERVICE_CONFIG_DESCRIPTION,
+ NULL,
+ 0,
+ &BytesNeeded))
+ {
+ if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
+ {
+ pServiceDescription = (SERVICE_DESCRIPTION *) HeapAlloc(ProcessHeap,
+ 0,
+ BytesNeeded);
+ if (pServiceDescription == NULL)
+ goto cleanup;
+
+ if (QueryServiceConfig2(hSc,
+ SERVICE_CONFIG_DESCRIPTION,
+ (LPBYTE)pServiceDescription,
+ BytesNeeded,
+ &BytesNeeded))
+ {
+ if (pServiceDescription->lpDescription)
+ {
+ lpDescription = HeapAlloc(ProcessHeap,
+ 0,
+
(_tcslen(pServiceDescription->lpDescription) + 1) * sizeof(TCHAR));
+ if (lpDescription)
+ _tcscpy(lpDescription,
+ pServiceDescription->lpDescription);
+ }
+ }
+ }
+ }
+ }
+
+cleanup:
+ if (pServiceDescription)
+ HeapFree(ProcessHeap,
+ 0,
+ pServiceDescription);
+ if (hSCManager != NULL)
+ CloseServiceHandle(hSCManager);
+ if (hSc != NULL)
+ CloseServiceHandle(hSc);
+
+ return lpDescription;
+}
+
+
static BOOL
@@ -206,6 +271,7 @@
RefreshServiceList(PMAIN_WND_INFO Info)
{
ENUM_SERVICE_STATUS_PROCESS *pService;
+ LPTSTR lpDescription;
LVITEM lvItem;
TCHAR szNumServices[32];
TCHAR szStatus[64];
@@ -223,7 +289,6 @@
for (Index = 0; Index < NumServices; Index++)
{
HKEY hKey = NULL;
- LPTSTR lpDescription = NULL;
LPTSTR lpLogOnAs = NULL;
DWORD StartUp = 0;
DWORD dwValueSize;
@@ -260,7 +325,7 @@
lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
/* set the description */
- if ((lpDescription = GetDescription(pService->lpServiceName)))
+ if ((lpDescription = GetServiceDescription(pService->lpServiceName)))
{
lvItem.pszText = lpDescription;
lvItem.iSubItem = 1;
Modified: trunk/reactos/base/applications/mscutils/servman/reg.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/mscutils…
==============================================================================
--- trunk/reactos/base/applications/mscutils/servman/reg.c (original)
+++ trunk/reactos/base/applications/mscutils/servman/reg.c Tue Aug 28 18:49:47 2007
@@ -57,46 +57,3 @@
return bRet;
}
-
-
-LPTSTR
-GetDescription(LPTSTR lpServiceName)
-{
- HKEY hKey;
- LPTSTR lpDescription = NULL;
- DWORD dwValueSize = 0;
-
- hKey = OpenServiceKey(lpServiceName);
- if (hKey)
- {
- if (RegQueryValueEx(hKey,
- _T("Description"),
- NULL,
- NULL,
- NULL,
- &dwValueSize) == ERROR_SUCCESS)
- {
- lpDescription = HeapAlloc(ProcessHeap,
- 0,
- dwValueSize);
- if (lpDescription)
- {
- if(RegQueryValueEx(hKey,
- _T("Description"),
- NULL,
- NULL,
- (LPBYTE)lpDescription,
- &dwValueSize) != ERROR_SUCCESS)
- {
- HeapFree(ProcessHeap,
- 0,
- lpDescription);
- }
- }
- }
-
- RegCloseKey(hKey);
- }
-
- return lpDescription;
-}