mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 04:33:32 +00:00
simplify some code
svn path=/trunk/; revision=28472
This commit is contained in:
parent
520d244fe2
commit
0c529df2e0
5 changed files with 207 additions and 201 deletions
|
@ -304,6 +304,58 @@ pCreateToolbar(PMAIN_WND_INFO Info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static VOID
|
||||||
|
InitListViewImage(PMAIN_WND_INFO Info)
|
||||||
|
{
|
||||||
|
HICON hSmIconItem, hLgIconItem; /* icon for list-view items */
|
||||||
|
HIMAGELIST hSmall, hLarge; /* image list for other views */
|
||||||
|
|
||||||
|
|
||||||
|
/* Create the icon image lists */
|
||||||
|
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
|
||||||
|
GetSystemMetrics(SM_CYSMICON),
|
||||||
|
ILC_MASK | ILC_COLOR32,
|
||||||
|
1,
|
||||||
|
1);
|
||||||
|
|
||||||
|
hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
|
||||||
|
GetSystemMetrics(SM_CYICON),
|
||||||
|
ILC_MASK | ILC_COLOR32,
|
||||||
|
1,
|
||||||
|
1);
|
||||||
|
|
||||||
|
/* Add an icon to each image list */
|
||||||
|
hSmIconItem = LoadImage(hInstance,
|
||||||
|
MAKEINTRESOURCE(IDI_SM_ICON),
|
||||||
|
IMAGE_ICON,
|
||||||
|
16,
|
||||||
|
16,
|
||||||
|
0);
|
||||||
|
|
||||||
|
ImageList_AddIcon(hSmall,
|
||||||
|
hSmIconItem);
|
||||||
|
|
||||||
|
hLgIconItem = LoadImage(hInstance,
|
||||||
|
MAKEINTRESOURCE(IDI_SM_ICON),
|
||||||
|
IMAGE_ICON,
|
||||||
|
32,
|
||||||
|
32,
|
||||||
|
0);
|
||||||
|
|
||||||
|
ImageList_AddIcon(hLarge,
|
||||||
|
hLgIconItem);
|
||||||
|
|
||||||
|
/* assign the image to the list view */
|
||||||
|
(void)ListView_SetImageList(Info->hListView,
|
||||||
|
hSmall,
|
||||||
|
LVSIL_SMALL);
|
||||||
|
(void)ListView_SetImageList(Info->hListView,
|
||||||
|
hLarge,
|
||||||
|
LVSIL_NORMAL);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
CreateListView(PMAIN_WND_INFO Info)
|
CreateListView(PMAIN_WND_INFO Info)
|
||||||
{
|
{
|
||||||
|
@ -397,6 +449,8 @@ CreateListView(PMAIN_WND_INFO Info)
|
||||||
4,
|
4,
|
||||||
&lvc);
|
&lvc);
|
||||||
|
|
||||||
|
InitListViewImage(Info);
|
||||||
|
|
||||||
/* check the details view menu item */
|
/* check the details view menu item */
|
||||||
CheckMenuRadioItem(GetMenu(Info->hMainWnd),
|
CheckMenuRadioItem(GetMenu(Info->hMainWnd),
|
||||||
ID_VIEW_LARGE,
|
ID_VIEW_LARGE,
|
||||||
|
|
|
@ -59,7 +59,7 @@ typedef struct _MAIN_WND_INFO
|
||||||
struct _PROP_DLG_INFO *PropSheet;
|
struct _PROP_DLG_INFO *PropSheet;
|
||||||
|
|
||||||
/* status flags */
|
/* status flags */
|
||||||
BOOL InMenuLoop : 1;
|
BOOL InMenuLoop;
|
||||||
|
|
||||||
} MAIN_WND_INFO, *PMAIN_WND_INFO;
|
} MAIN_WND_INFO, *PMAIN_WND_INFO;
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ BOOL Control(PMAIN_WND_INFO Info, DWORD Control);
|
||||||
/* query.c */
|
/* query.c */
|
||||||
ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info);
|
ENUM_SERVICE_STATUS_PROCESS* GetSelectedService(PMAIN_WND_INFO Info);
|
||||||
BOOL SetDescription(LPTSTR, LPTSTR);
|
BOOL SetDescription(LPTSTR, LPTSTR);
|
||||||
BOOL GetDescription(LPTSTR, LPTSTR *);
|
LPTSTR GetDescription(LPTSTR);
|
||||||
BOOL GetExecutablePath(PMAIN_WND_INFO Info, LPTSTR *);
|
LPTSTR GetExecutablePath(PMAIN_WND_INFO Info);
|
||||||
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
|
BOOL RefreshServiceList(PMAIN_WND_INFO Info);
|
||||||
DWORD GetServiceList(PMAIN_WND_INFO Info);
|
DWORD GetServiceList(PMAIN_WND_INFO Info);
|
||||||
|
|
||||||
|
|
|
@ -125,20 +125,24 @@ GetDlgInfo(PMAIN_WND_INFO Info)
|
||||||
(LPARAM)Info->PropSheet->lpDisplayName);
|
(LPARAM)Info->PropSheet->lpDisplayName);
|
||||||
|
|
||||||
/* set the description */
|
/* set the description */
|
||||||
if (GetDescription(Info->CurrentService->lpServiceName, &Info->PropSheet->lpDescription))
|
if (Info->PropSheet->lpDescription = GetDescription(Info->CurrentService->lpServiceName))
|
||||||
|
{
|
||||||
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
|
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
|
||||||
IDC_DESCRIPTION,
|
IDC_DESCRIPTION,
|
||||||
WM_SETTEXT,
|
WM_SETTEXT,
|
||||||
0,
|
0,
|
||||||
(LPARAM)Info->PropSheet->lpDescription);
|
(LPARAM)Info->PropSheet->lpDescription);
|
||||||
|
}
|
||||||
|
|
||||||
/* set the executable path */
|
/* set the executable path */
|
||||||
if (GetExecutablePath(Info, &Info->PropSheet->lpPathToExe))
|
if (Info->PropSheet->lpPathToExe = GetExecutablePath(Info))
|
||||||
|
{
|
||||||
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
|
SendDlgItemMessage(Info->PropSheet->hwndGenDlg,
|
||||||
IDC_EXEPATH,
|
IDC_EXEPATH,
|
||||||
WM_SETTEXT,
|
WM_SETTEXT,
|
||||||
0,
|
0,
|
||||||
(LPARAM)Info->PropSheet->lpPathToExe);
|
(LPARAM)Info->PropSheet->lpPathToExe);
|
||||||
|
}
|
||||||
|
|
||||||
/* set startup type */
|
/* set startup type */
|
||||||
SetStartupType(Info);
|
SetStartupType(Info);
|
||||||
|
@ -182,8 +186,8 @@ GetDlgInfo(PMAIN_WND_INFO Info)
|
||||||
static INT_PTR CALLBACK
|
static INT_PTR CALLBACK
|
||||||
GeneralPageProc(HWND hwndDlg,
|
GeneralPageProc(HWND hwndDlg,
|
||||||
UINT uMsg,
|
UINT uMsg,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
LPARAM lParam)
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
PMAIN_WND_INFO Info;
|
PMAIN_WND_INFO Info;
|
||||||
|
|
||||||
|
@ -247,6 +251,16 @@ GeneralPageProc(HWND hwndDlg,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
|
if (Info->PropSheet->lpDescription)
|
||||||
|
HeapFree(ProcessHeap,
|
||||||
|
0,
|
||||||
|
Info->PropSheet->lpDescription);
|
||||||
|
|
||||||
|
if (Info->PropSheet->lpPathToExe)
|
||||||
|
HeapFree(ProcessHeap,
|
||||||
|
0,
|
||||||
|
Info->PropSheet->lpPathToExe);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_NOTIFY:
|
case WM_NOTIFY:
|
||||||
|
|
|
@ -27,115 +27,16 @@ GetSelectedService(PMAIN_WND_INFO Info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Sets the service description in the registry */
|
|
||||||
BOOL SetDescription(LPTSTR ServiceName, LPTSTR Description)
|
|
||||||
{
|
|
||||||
HKEY hKey;
|
|
||||||
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
|
||||||
TCHAR buf[300];
|
|
||||||
TCHAR szBuf[MAX_PATH];
|
|
||||||
LONG val;
|
|
||||||
|
|
||||||
|
|
||||||
/* open the registry key for the service */
|
|
||||||
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, ServiceName);
|
|
||||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
|
||||||
buf,
|
|
||||||
0,
|
|
||||||
KEY_WRITE,
|
|
||||||
&hKey);
|
|
||||||
|
|
||||||
|
|
||||||
if ((val = RegSetValueEx(hKey,
|
|
||||||
_T("Description"),
|
|
||||||
0,
|
|
||||||
REG_SZ,
|
|
||||||
(LPBYTE)Description,
|
|
||||||
(DWORD)lstrlen(szBuf)+1)) != ERROR_SUCCESS)
|
|
||||||
{
|
|
||||||
//GetError(val);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Retrives the service description from the registry */
|
|
||||||
BOOL GetDescription(LPTSTR lpServiceName, LPTSTR *retDescription)
|
|
||||||
{
|
|
||||||
HKEY hKey;
|
|
||||||
LPTSTR Description = NULL;
|
|
||||||
DWORD dwValueSize = 0;
|
|
||||||
LONG ret;
|
|
||||||
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
|
||||||
TCHAR buf[300];
|
|
||||||
|
|
||||||
/* open the registry key for the service */
|
|
||||||
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, lpServiceName);
|
|
||||||
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
|
||||||
buf,
|
|
||||||
0,
|
|
||||||
KEY_READ,
|
|
||||||
&hKey);
|
|
||||||
|
|
||||||
ret = RegQueryValueEx(hKey,
|
|
||||||
_T("Description"),
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&dwValueSize);
|
|
||||||
if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret != ERROR_INVALID_HANDLE)
|
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret != ERROR_FILE_NOT_FOUND)
|
|
||||||
{
|
|
||||||
Description = HeapAlloc(ProcessHeap,
|
|
||||||
HEAP_ZERO_MEMORY,
|
|
||||||
dwValueSize);
|
|
||||||
if (Description == NULL)
|
|
||||||
{
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(RegQueryValueEx(hKey,
|
|
||||||
_T("Description"),
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
(LPBYTE)Description,
|
|
||||||
&dwValueSize))
|
|
||||||
{
|
|
||||||
HeapFree(ProcessHeap,
|
|
||||||
0,
|
|
||||||
Description);
|
|
||||||
RegCloseKey(hKey);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* copy pointer over */
|
|
||||||
*retDescription = Description;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* get vendor of service binary */
|
/* get vendor of service binary */
|
||||||
BOOL
|
LPTSTR
|
||||||
GetExecutablePath(PMAIN_WND_INFO Info,
|
GetExecutablePath(PMAIN_WND_INFO Info)
|
||||||
LPTSTR *ExePath)
|
|
||||||
{
|
{
|
||||||
SC_HANDLE hSCManager = NULL;
|
SC_HANDLE hSCManager = NULL;
|
||||||
SC_HANDLE hSc = NULL;
|
SC_HANDLE hSc = NULL;
|
||||||
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
|
LPQUERY_SERVICE_CONFIG pServiceConfig = NULL;
|
||||||
DWORD BytesNeeded = 0;
|
DWORD BytesNeeded = 0;
|
||||||
|
LPTSTR lpExePath = NULL;
|
||||||
|
|
||||||
/* open handle to the SCM */
|
/* open handle to the SCM */
|
||||||
hSCManager = OpenSCManager(NULL,
|
hSCManager = OpenSCManager(NULL,
|
||||||
|
@ -157,7 +58,6 @@ GetExecutablePath(PMAIN_WND_INFO Info,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!QueryServiceConfig(hSc,
|
if (!QueryServiceConfig(hSc,
|
||||||
pServiceConfig,
|
pServiceConfig,
|
||||||
0,
|
0,
|
||||||
|
@ -165,99 +65,40 @@ GetExecutablePath(PMAIN_WND_INFO Info,
|
||||||
{
|
{
|
||||||
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||||
{
|
{
|
||||||
pServiceConfig = (LPQUERY_SERVICE_CONFIG)
|
pServiceConfig = (LPQUERY_SERVICE_CONFIG) HeapAlloc(ProcessHeap,
|
||||||
HeapAlloc(ProcessHeap,
|
0,
|
||||||
0,
|
BytesNeeded);
|
||||||
BytesNeeded);
|
|
||||||
if (pServiceConfig == NULL)
|
if (pServiceConfig == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!QueryServiceConfig(hSc,
|
if (QueryServiceConfig(hSc,
|
||||||
pServiceConfig,
|
pServiceConfig,
|
||||||
BytesNeeded,
|
BytesNeeded,
|
||||||
&BytesNeeded))
|
&BytesNeeded))
|
||||||
{
|
{
|
||||||
HeapFree(ProcessHeap,
|
lpExePath = HeapAlloc(ProcessHeap,
|
||||||
0,
|
0,
|
||||||
pServiceConfig);
|
(_tcslen(pServiceConfig->lpBinaryPathName) +1 ) * sizeof(TCHAR));
|
||||||
goto cleanup;
|
|
||||||
|
_tcscpy(lpExePath, pServiceConfig->lpBinaryPathName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else /* exit on failure */
|
|
||||||
{
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*ExePath = pServiceConfig->lpBinaryPathName;
|
|
||||||
|
|
||||||
CloseServiceHandle(hSCManager);
|
|
||||||
CloseServiceHandle(hSc);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (pServiceConfig)
|
||||||
|
HeapFree(ProcessHeap,
|
||||||
|
0,
|
||||||
|
pServiceConfig);
|
||||||
if (hSCManager != NULL)
|
if (hSCManager != NULL)
|
||||||
CloseServiceHandle(hSCManager);
|
CloseServiceHandle(hSCManager);
|
||||||
if (hSc != NULL)
|
if (hSc != NULL)
|
||||||
CloseServiceHandle(hSc);
|
CloseServiceHandle(hSc);
|
||||||
return FALSE;
|
|
||||||
|
return lpExePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static VOID
|
|
||||||
InitListViewImage(PMAIN_WND_INFO Info)
|
|
||||||
{
|
|
||||||
HICON hSmIconItem, hLgIconItem; /* icon for list-view items */
|
|
||||||
HIMAGELIST hSmall, hLarge; /* image list for other views */
|
|
||||||
|
|
||||||
|
|
||||||
/* Create the icon image lists */
|
|
||||||
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
|
|
||||||
GetSystemMetrics(SM_CYSMICON),
|
|
||||||
ILC_MASK | ILC_COLOR32,
|
|
||||||
1,
|
|
||||||
1);
|
|
||||||
|
|
||||||
hLarge = ImageList_Create(GetSystemMetrics(SM_CXICON),
|
|
||||||
GetSystemMetrics(SM_CYICON),
|
|
||||||
ILC_MASK | ILC_COLOR32,
|
|
||||||
1,
|
|
||||||
1);
|
|
||||||
|
|
||||||
/* Add an icon to each image list */
|
|
||||||
hSmIconItem = LoadImage(hInstance,
|
|
||||||
MAKEINTRESOURCE(IDI_SM_ICON),
|
|
||||||
IMAGE_ICON,
|
|
||||||
16,
|
|
||||||
16,
|
|
||||||
0);
|
|
||||||
|
|
||||||
ImageList_AddIcon(hSmall,
|
|
||||||
hSmIconItem);
|
|
||||||
|
|
||||||
hLgIconItem = LoadImage(hInstance,
|
|
||||||
MAKEINTRESOURCE(IDI_SM_ICON),
|
|
||||||
IMAGE_ICON,
|
|
||||||
32,
|
|
||||||
32,
|
|
||||||
0);
|
|
||||||
|
|
||||||
ImageList_AddIcon(hLarge,
|
|
||||||
hLgIconItem);
|
|
||||||
|
|
||||||
/* assign the image to the list view */
|
|
||||||
(void)ListView_SetImageList(Info->hListView,
|
|
||||||
hSmall,
|
|
||||||
LVSIL_SMALL);
|
|
||||||
(void)ListView_SetImageList(Info->hListView,
|
|
||||||
hLarge,
|
|
||||||
LVSIL_NORMAL);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
RefreshServiceList(PMAIN_WND_INFO Info)
|
RefreshServiceList(PMAIN_WND_INFO Info)
|
||||||
{
|
{
|
||||||
|
@ -270,8 +111,6 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
||||||
|
|
||||||
(void)ListView_DeleteAllItems(Info->hListView);
|
(void)ListView_DeleteAllItems(Info->hListView);
|
||||||
|
|
||||||
InitListViewImage(Info);
|
|
||||||
|
|
||||||
NumServices = GetServiceList(Info);
|
NumServices = GetServiceList(Info);
|
||||||
|
|
||||||
if (NumServices)
|
if (NumServices)
|
||||||
|
@ -282,7 +121,7 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
||||||
for (Index = 0; Index < NumServices; Index++)
|
for (Index = 0; Index < NumServices; Index++)
|
||||||
{
|
{
|
||||||
HKEY hKey = NULL;
|
HKEY hKey = NULL;
|
||||||
LPTSTR Description = NULL;
|
LPTSTR lpDescription = NULL;
|
||||||
LPTSTR LogOnAs = NULL;
|
LPTSTR LogOnAs = NULL;
|
||||||
DWORD StartUp = 0;
|
DWORD StartUp = 0;
|
||||||
DWORD dwValueSize;
|
DWORD dwValueSize;
|
||||||
|
@ -313,12 +152,10 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
||||||
lvItem.iItem = ListView_GetItemCount(Info->hListView);
|
lvItem.iItem = ListView_GetItemCount(Info->hListView);
|
||||||
lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
|
lvItem.iItem = ListView_InsertItem(Info->hListView, &lvItem);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* set the description */
|
/* set the description */
|
||||||
if (GetDescription(Info->pServiceStatus[Index].lpServiceName, &Description))
|
if (lpDescription = GetDescription(Info->pServiceStatus[Index].lpServiceName))
|
||||||
{
|
{
|
||||||
lvItem.pszText = Description;
|
lvItem.pszText = lpDescription;
|
||||||
lvItem.iSubItem = 1;
|
lvItem.iSubItem = 1;
|
||||||
SendMessage(Info->hListView,
|
SendMessage(Info->hListView,
|
||||||
LVM_SETITEMTEXT,
|
LVM_SETITEMTEXT,
|
||||||
|
@ -327,10 +164,9 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
||||||
|
|
||||||
HeapFree(ProcessHeap,
|
HeapFree(ProcessHeap,
|
||||||
0,
|
0,
|
||||||
Description);
|
lpDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* set the status */
|
/* set the status */
|
||||||
if (Info->pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
|
if (Info->pServiceStatus[Index].ServiceStatusProcess.dwCurrentState == SERVICE_RUNNING)
|
||||||
{
|
{
|
||||||
|
@ -346,8 +182,6 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
||||||
(LPARAM)&lvItem);
|
(LPARAM)&lvItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* set the startup type */
|
/* set the startup type */
|
||||||
dwValueSize = sizeof(DWORD);
|
dwValueSize = sizeof(DWORD);
|
||||||
if (RegQueryValueEx(hKey,
|
if (RegQueryValueEx(hKey,
|
||||||
|
@ -401,8 +235,6 @@ RefreshServiceList(PMAIN_WND_INFO Info)
|
||||||
(LPARAM)&lvItem);
|
(LPARAM)&lvItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* set Log On As */
|
/* set Log On As */
|
||||||
dwValueSize = 0;
|
dwValueSize = 0;
|
||||||
if (RegQueryValueEx(hKey,
|
if (RegQueryValueEx(hKey,
|
||||||
|
@ -515,7 +347,7 @@ GetServiceList(PMAIN_WND_INFO Info)
|
||||||
0,
|
0,
|
||||||
BytesNeeded);
|
BytesNeeded);
|
||||||
if (Info->pServiceStatus == NULL)
|
if (Info->pServiceStatus == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* fill array with service info */
|
/* fill array with service info */
|
||||||
if (EnumServicesStatusEx(ScHandle,
|
if (EnumServicesStatusEx(ScHandle,
|
||||||
|
|
106
reactos/base/applications/mscutils/servman/reg.c
Normal file
106
reactos/base/applications/mscutils/servman/reg.c
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
* PROJECT: ReactOS Services
|
||||||
|
* LICENSE: GPL - See COPYING in the top level directory
|
||||||
|
* FILE: base/system/servman/reg.c
|
||||||
|
* PURPOSE: Query service information
|
||||||
|
* COPYRIGHT: Copyright 2005 - 2007 Ged Murphy <gedmurphy@gmail.com>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "precomp.h"
|
||||||
|
|
||||||
|
/* Sets the service description in the registry */
|
||||||
|
BOOL SetDescription(LPTSTR ServiceName, LPTSTR Description)
|
||||||
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
||||||
|
TCHAR buf[300];
|
||||||
|
TCHAR szBuf[MAX_PATH];
|
||||||
|
LONG val;
|
||||||
|
|
||||||
|
|
||||||
|
/* open the registry key for the service */
|
||||||
|
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, ServiceName);
|
||||||
|
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||||
|
buf,
|
||||||
|
0,
|
||||||
|
KEY_WRITE,
|
||||||
|
&hKey);
|
||||||
|
|
||||||
|
|
||||||
|
if ((val = RegSetValueEx(hKey,
|
||||||
|
_T("Description"),
|
||||||
|
0,
|
||||||
|
REG_SZ,
|
||||||
|
(LPBYTE)Description,
|
||||||
|
(DWORD)lstrlen(szBuf)+1)) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
//GetError(val);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Retrives the service description from the registry */
|
||||||
|
LPTSTR
|
||||||
|
GetDescription(LPTSTR lpServiceName)
|
||||||
|
{
|
||||||
|
HKEY hKey;
|
||||||
|
LPTSTR lpDescription = NULL;
|
||||||
|
DWORD dwValueSize = 0;
|
||||||
|
LONG ret;
|
||||||
|
LPCTSTR Path = _T("System\\CurrentControlSet\\Services\\%s");
|
||||||
|
TCHAR buf[300];
|
||||||
|
|
||||||
|
/* open the registry key for the service */
|
||||||
|
_sntprintf(buf, sizeof(buf) / sizeof(TCHAR), Path, lpServiceName);
|
||||||
|
RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||||
|
buf,
|
||||||
|
0,
|
||||||
|
KEY_READ,
|
||||||
|
&hKey);
|
||||||
|
|
||||||
|
ret = RegQueryValueEx(hKey,
|
||||||
|
_T("Description"),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&dwValueSize);
|
||||||
|
if (ret != ERROR_SUCCESS && ret != ERROR_FILE_NOT_FOUND && ret != ERROR_INVALID_HANDLE)
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != ERROR_FILE_NOT_FOUND)
|
||||||
|
{
|
||||||
|
lpDescription = HeapAlloc(ProcessHeap,
|
||||||
|
HEAP_ZERO_MEMORY,
|
||||||
|
dwValueSize);
|
||||||
|
if (lpDescription == NULL)
|
||||||
|
{
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(RegQueryValueEx(hKey,
|
||||||
|
_T("Description"),
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
(LPBYTE)lpDescription,
|
||||||
|
&dwValueSize))
|
||||||
|
{
|
||||||
|
HeapFree(ProcessHeap,
|
||||||
|
0,
|
||||||
|
lpDescription);
|
||||||
|
RegCloseKey(hKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lpDescription;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue