From 5bdb637cb7626227ecb6ffcfec075908b6675524 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Thu, 30 Aug 2007 12:27:11 +0000 Subject: [PATCH] - implement setting the service description - fix deleting of a service svn path=/trunk/; revision=28670 --- .../applications/mscutils/servman/create.c | 8 +- .../applications/mscutils/servman/delete.c | 134 +++++++++--------- .../applications/mscutils/servman/precomp.h | 1 + .../applications/mscutils/servman/query.c | 47 ++++++ .../applications/mscutils/servman/servman.c | 3 - 5 files changed, 118 insertions(+), 75 deletions(-) diff --git a/reactos/base/applications/mscutils/servman/create.c b/reactos/base/applications/mscutils/servman/create.c index 1601ab0e553..433b802a8d5 100644 --- a/reactos/base/applications/mscutils/servman/create.c +++ b/reactos/base/applications/mscutils/servman/create.c @@ -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, diff --git a/reactos/base/applications/mscutils/servman/delete.c b/reactos/base/applications/mscutils/servman/delete.c index e6e732ed833..cf5c85502aa 100644 --- a/reactos/base/applications/mscutils/servman/delete.c +++ b/reactos/base/applications/mscutils/servman/delete.c @@ -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 + * COPYRIGHT: Copyright 2006-2007 Ged Murphy * */ @@ -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; diff --git a/reactos/base/applications/mscutils/servman/precomp.h b/reactos/base/applications/mscutils/servman/precomp.h index bc5f50381dd..8e7ebffb99f 100644 --- a/reactos/base/applications/mscutils/servman/precomp.h +++ b/reactos/base/applications/mscutils/servman/precomp.h @@ -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); diff --git a/reactos/base/applications/mscutils/servman/query.c b/reactos/base/applications/mscutils/servman/query.c index 9bdbfb702f3..d14347f3ba3 100644 --- a/reactos/base/applications/mscutils/servman/query.c +++ b/reactos/base/applications/mscutils/servman/query.c @@ -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, diff --git a/reactos/base/applications/mscutils/servman/servman.c b/reactos/base/applications/mscutils/servman/servman.c index 94ff89afe42..47afa1ebbca 100644 --- a/reactos/base/applications/mscutils/servman/servman.c +++ b/reactos/base/applications/mscutils/servman/servman.c @@ -64,6 +64,3 @@ _tWinMain(HINSTANCE hThisInstance, return Ret; } - - -