- implement setting the service description

- fix deleting of a service

svn path=/trunk/; revision=28670
This commit is contained in:
Ged Murphy
2007-08-30 12:27:11 +00:00
parent 4862094dd0
commit 5bdb637cb7
5 changed files with 118 additions and 75 deletions
@@ -60,10 +60,10 @@ DoCreate(PCREATE_DATA Data)
return FALSE;
}
/* Set the service description in the registry
* CreateService does not do this for us */
//SetDescription(Data->ServiceName,
// Data->Description);
/* Set the service description as CreateService
does not do this for us */
SetServiceDescription(Data->ServiceName,
Data->Description);
/* report success to user */
LoadString(hInstance,
@@ -1,9 +1,9 @@
/*
* PROJECT: ReactOS Services
* LICENSE: GPL - See COPYING in the top level directory
* FILE: base/system/servman/delete.c
* FILE: base/applications/mscutils/servman/delete.c
* PURPOSE: Delete an existing service
* COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
* COPYRIGHT: Copyright 2006-2007 Ged Murphy <gedmurphy@reactos.org>
*
*/
@@ -15,42 +15,30 @@ DoDeleteService(PMAIN_WND_INFO Info,
{
SC_HANDLE hSCManager;
SC_HANDLE hSc;
BOOL bRet = FALSE;
/* open handle to the SCM */
hSCManager = OpenSCManager(NULL,
NULL,
SC_MANAGER_ALL_ACCESS);
if (hSCManager == NULL)
if (hSCManager)
{
GetError();
return FALSE;
}
hSc = OpenService(hSCManager,
Info->pCurrentService->lpServiceName,
DELETE);
if (hSc)
{
if (DeleteService(hSc))
{
bRet = TRUE;
}
CloseServiceHandle(hSc);
}
/* get a handle to the service requested for deleting */
hSc = OpenService(hSCManager,
Info->pCurrentService->lpServiceName,
DELETE);
if (hSc == NULL)
{
GetError();
CloseServiceHandle(hSCManager);
return FALSE;
}
/* delete the service opened */
if (! DeleteService(hSc))
{
GetError();
CloseServiceHandle(hSCManager);
CloseServiceHandle(hSc);
return FALSE;
}
CloseServiceHandle(hSCManager);
CloseServiceHandle(hSc);
return TRUE;
return bRet;
}
@@ -62,53 +50,66 @@ DeleteDialogProc(HWND hDlg,
{
PMAIN_WND_INFO Info = NULL;
HICON hIcon = NULL;
TCHAR Buf[1000];
LVITEM item;
/* Get the window context */
Info = (PMAIN_WND_INFO)GetWindowLongPtr(hDlg,
GWLP_USERDATA);
if (Info == NULL && message != WM_INITDIALOG)
{
return FALSE;
}
switch (message)
{
case WM_INITDIALOG:
{
LPTSTR lpDescription;
Info = (PMAIN_WND_INFO)lParam;
if (Info != NULL)
{
SetWindowLongPtr(hDlg,
GWLP_USERDATA,
(LONG_PTR)Info);
hIcon = (HICON) LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
hIcon = (HICON)LoadImage(hInstance,
MAKEINTRESOURCE(IDI_SM_ICON),
IMAGE_ICON,
16,
16,
0);
if (hIcon)
{
SendMessage(hDlg,
WM_SETICON,
ICON_SMALL,
(LPARAM)hIcon);
DestroyIcon(hIcon);
}
SendMessage(hDlg,
WM_SETICON,
ICON_SMALL,
(LPARAM)hIcon);
SendDlgItemMessage(hDlg,
IDC_DEL_NAME,
WM_SETTEXT,
0,
(LPARAM)Info->pCurrentService->lpDisplayName);
SendDlgItemMessage(hDlg,
IDC_DEL_NAME,
WM_SETTEXT,
0,
(LPARAM)Info->pCurrentService->lpDisplayName);
lpDescription = GetServiceDescription(Info->pCurrentService->lpServiceName);
if (lpDescription)
{
SendDlgItemMessage(hDlg,
IDC_DEL_DESC,
WM_SETTEXT,
0,
(LPARAM)lpDescription);
HeapFree(ProcessHeap,
0,
lpDescription);
}
return TRUE;
}
item.mask = LVIF_TEXT;
item.iItem = Info->SelectedItem;
item.iSubItem = 1;
item.pszText = Buf;
item.cchTextMax = sizeof(Buf);
SendMessage(Info->hListView,
LVM_GETITEM,
0,
(LPARAM)&item);
SendDlgItemMessage(hDlg,
IDC_DEL_DESC,
WM_SETTEXT,
0,
(LPARAM)Buf);
SetFocus(GetDlgItem(hDlg, IDCANCEL));
return TRUE;
return FALSE;
}
case WM_COMMAND:
@@ -120,8 +121,6 @@ DeleteDialogProc(HWND hDlg,
if (DoDeleteService(Info, hDlg))
(void)ListView_DeleteItem(Info->hListView,
Info->SelectedItem);
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
@@ -129,7 +128,6 @@ DeleteDialogProc(HWND hDlg,
case IDCANCEL:
{
DestroyIcon(hIcon);
EndDialog(hDlg,
LOWORD(wParam));
return TRUE;
@@ -88,6 +88,7 @@ ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info);
LPQUERY_SERVICE_CONFIG GetServiceConfig(LPTSTR lpServiceName);
BOOL SetServiceConfig(LPQUERY_SERVICE_CONFIG pServiceConfig, LPTSTR lpServiceName, LPTSTR lpPassword);
LPTSTR GetServiceDescription(LPTSTR lpServiceName);
BOOL SetServiceDescription(LPTSTR lpServiceName, LPTSTR lpDescription);
LPTSTR GetExecutablePath(LPTSTR lpServiceName);
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
BOOL UpdateServiceStatus(ENUM_SERVICE_STATUS_PROCESS* pService);
@@ -211,6 +211,53 @@ cleanup:
}
BOOL
SetServiceDescription(LPTSTR lpServiceName,
LPTSTR lpDescription)
{
SC_HANDLE hSCManager;
SC_HANDLE hSc;
SC_LOCK scLock;
SERVICE_DESCRIPTION ServiceDescription;
BOOL bRet = FALSE;
hSCManager = OpenSCManager(NULL,
NULL,
SC_MANAGER_LOCK);
if (hSCManager)
{
scLock = LockServiceDatabase(hSCManager);
if (scLock)
{
hSc = OpenService(hSCManager,
lpServiceName,
SERVICE_CHANGE_CONFIG);
if (hSc)
{
ServiceDescription.lpDescription = lpDescription;
if (ChangeServiceConfig2(hSc,
SERVICE_CONFIG_DESCRIPTION,
&ServiceDescription))
{
bRet = TRUE;
}
CloseServiceHandle(hSc);
}
UnlockServiceDatabase(scLock);
}
CloseServiceHandle(hSCManager);
}
if (!bRet)
GetError();
return bRet;
}
BOOL
GetServiceList(PMAIN_WND_INFO Info,
@@ -64,6 +64,3 @@ _tWinMain(HINSTANCE hThisInstance,
return Ret;
}