mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
* added create service dialog
* cache some PhGetProcAddress results git-svn-id: svn://svn.code.sf.net/p/processhacker/code@3160 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
@@ -516,6 +516,10 @@
|
||||
RelativePath=".\settings.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\srvcr.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\srvprp.c"
|
||||
>
|
||||
|
||||
@@ -168,10 +168,11 @@ BOOLEAN PhUiConnectSession(
|
||||
__in ULONG SessionId
|
||||
)
|
||||
{
|
||||
_WinStationConnectW WinStationConnectW_I;
|
||||
static _WinStationConnectW WinStationConnectW_I = NULL;
|
||||
PPH_STRING selectedChoice = NULL;
|
||||
|
||||
WinStationConnectW_I = PhGetProcAddress(L"winsta.dll", "WinStationConnectW");
|
||||
if (!WinStationConnectW_I)
|
||||
WinStationConnectW_I = PhGetProcAddress(L"winsta.dll", "WinStationConnectW");
|
||||
|
||||
if (!WinStationConnectW_I)
|
||||
{
|
||||
|
||||
@@ -821,6 +821,12 @@ VOID PhShowSessionProperties(
|
||||
__in ULONG SessionId
|
||||
);
|
||||
|
||||
// srvcr
|
||||
|
||||
VOID PhShowCreateServiceDialog(
|
||||
__in HWND ParentWindowHandle
|
||||
);
|
||||
|
||||
// srvprp
|
||||
|
||||
VOID PhShowServiceProperties(
|
||||
|
||||
@@ -638,6 +638,11 @@ LRESULT CALLBACK PhMainWndProc(
|
||||
);
|
||||
}
|
||||
break;
|
||||
case ID_TOOLS_CREATESERVICE:
|
||||
{
|
||||
PhShowCreateServiceDialog(hWnd);
|
||||
}
|
||||
break;
|
||||
case ID_TOOLS_HIDDENPROCESSES:
|
||||
{
|
||||
PhShowHiddenProcessesDialog();
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Process Hacker -
|
||||
* service creation dialog
|
||||
*
|
||||
* Copyright (C) 2010 wj32
|
||||
*
|
||||
* This file is part of Process Hacker.
|
||||
*
|
||||
* Process Hacker is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Process Hacker is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <phapp.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
INT_PTR CALLBACK PhpCreateServiceDlgProc(
|
||||
__in HWND hwndDlg,
|
||||
__in UINT uMsg,
|
||||
__in WPARAM wParam,
|
||||
__in LPARAM lParam
|
||||
);
|
||||
|
||||
VOID PhShowCreateServiceDialog(
|
||||
__in HWND ParentWindowHandle
|
||||
)
|
||||
{
|
||||
DialogBox(
|
||||
PhInstanceHandle,
|
||||
MAKEINTRESOURCE(IDD_CREATESERVICE),
|
||||
ParentWindowHandle,
|
||||
PhpCreateServiceDlgProc
|
||||
);
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK PhpCreateServiceDlgProc(
|
||||
__in HWND hwndDlg,
|
||||
__in UINT uMsg,
|
||||
__in WPARAM wParam,
|
||||
__in LPARAM lParam
|
||||
)
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
PhCenterWindow(hwndDlg, GetParent(hwndDlg));
|
||||
|
||||
PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_TYPE), PhServiceTypeStrings,
|
||||
sizeof(PhServiceTypeStrings) / sizeof(WCHAR *));
|
||||
PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_STARTTYPE), PhServiceStartTypeStrings,
|
||||
sizeof(PhServiceStartTypeStrings) / sizeof(WCHAR *));
|
||||
PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_ERRORCONTROL), PhServiceErrorControlStrings,
|
||||
sizeof(PhServiceErrorControlStrings) / sizeof(WCHAR *));
|
||||
|
||||
ComboBox_SelectString(GetDlgItem(hwndDlg, IDC_TYPE), -1, L"Own Process");
|
||||
ComboBox_SelectString(GetDlgItem(hwndDlg, IDC_STARTTYPE), -1, L"Demand Start");
|
||||
ComboBox_SelectString(GetDlgItem(hwndDlg, IDC_ERRORCONTROL), -1, L"Ignore");
|
||||
|
||||
SetFocus(GetDlgItem(hwndDlg, IDC_NAME));
|
||||
}
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
{
|
||||
switch (LOWORD(wParam))
|
||||
{
|
||||
case IDCANCEL:
|
||||
{
|
||||
EndDialog(hwndDlg, IDCANCEL);
|
||||
}
|
||||
break;
|
||||
case IDOK:
|
||||
{
|
||||
BOOLEAN success = FALSE;
|
||||
SC_HANDLE scManagerHandle;
|
||||
SC_HANDLE serviceHandle;
|
||||
ULONG win32Result;
|
||||
PPH_STRING serviceName;
|
||||
PPH_STRING serviceDisplayName;
|
||||
PPH_STRING serviceTypeString;
|
||||
PPH_STRING serviceStartTypeString;
|
||||
PPH_STRING serviceErrorControlString;
|
||||
ULONG serviceType;
|
||||
ULONG serviceStartType;
|
||||
ULONG serviceErrorControl;
|
||||
PPH_STRING serviceBinaryPath;
|
||||
|
||||
serviceName = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_NAME)));
|
||||
serviceDisplayName = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_DISPLAYNAME)));
|
||||
|
||||
serviceTypeString = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_TYPE)));
|
||||
serviceStartTypeString = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_STARTTYPE)));
|
||||
serviceErrorControlString = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_ERRORCONTROL)));
|
||||
serviceType = PhGetServiceTypeInteger(serviceTypeString->Buffer);
|
||||
serviceStartType = PhGetServiceStartTypeInteger(serviceStartTypeString->Buffer);
|
||||
serviceErrorControl = PhGetServiceErrorControlInteger(serviceErrorControlString->Buffer);
|
||||
|
||||
serviceBinaryPath = PHA_DEREFERENCE(PhGetWindowText(GetDlgItem(hwndDlg, IDC_BINARYPATH)));
|
||||
|
||||
if (scManagerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE))
|
||||
{
|
||||
if (serviceHandle = CreateService(
|
||||
scManagerHandle,
|
||||
serviceName->Buffer,
|
||||
serviceDisplayName->Buffer,
|
||||
SERVICE_CHANGE_CONFIG,
|
||||
serviceType,
|
||||
serviceStartType,
|
||||
serviceErrorControl,
|
||||
serviceBinaryPath->Buffer,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
L""
|
||||
))
|
||||
{
|
||||
EndDialog(hwndDlg, IDOK);
|
||||
CloseServiceHandle(serviceHandle);
|
||||
success = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
win32Result = GetLastError();
|
||||
}
|
||||
|
||||
CloseServiceHandle(scManagerHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
win32Result = GetLastError();
|
||||
}
|
||||
|
||||
if (!success)
|
||||
PhShowStatus(hwndDlg, L"Unable to create the service", 0, win32Result);
|
||||
}
|
||||
break;
|
||||
case IDC_BROWSE:
|
||||
{
|
||||
static PH_FILETYPE_FILTER filters[] =
|
||||
{
|
||||
{ L"Executable files (*.exe;*.sys)", L"*.exe;*.sys" },
|
||||
{ L"All files (*.*)", L"*.*" }
|
||||
};
|
||||
PVOID fileDialog;
|
||||
PPH_STRING fileName;
|
||||
|
||||
fileDialog = PhCreateOpenFileDialog();
|
||||
PhSetFileDialogFilter(fileDialog, filters, sizeof(filters) / sizeof(PH_FILETYPE_FILTER));
|
||||
|
||||
fileName = PhGetFileName(PHA_GET_DLGITEM_TEXT(hwndDlg, IDC_BINARYPATH));
|
||||
PhSetFileDialogFileName(fileDialog, fileName->Buffer);
|
||||
PhDereferenceObject(fileName);
|
||||
|
||||
if (PhShowFileDialog(NULL, fileDialog))
|
||||
{
|
||||
fileName = PhGetFileDialogFileName(fileDialog);
|
||||
SetDlgItemText(hwndDlg, IDC_BINARYPATH, fileName->Buffer);
|
||||
PhDereferenceObject(fileName);
|
||||
}
|
||||
|
||||
PhFreeFileDialog(fileDialog);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@@ -114,18 +114,6 @@ VOID PhShowServiceProperties(
|
||||
PropertySheet(&propSheetHeader);
|
||||
}
|
||||
|
||||
VOID PhpAddComboBoxItems(
|
||||
__in HWND hWnd,
|
||||
__in PWSTR *Items,
|
||||
__in ULONG NumberOfItems
|
||||
)
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
for (i = 0; i < NumberOfItems; i++)
|
||||
ComboBox_AddString(hWnd, Items[i]);
|
||||
}
|
||||
|
||||
INT_PTR CALLBACK PhpServiceGeneralDlgProc(
|
||||
__in HWND hwndDlg,
|
||||
__in UINT uMsg,
|
||||
@@ -137,11 +125,6 @@ INT_PTR CALLBACK PhpServiceGeneralDlgProc(
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
{
|
||||
WCHAR *serviceTypeItems[] = { L"Driver", L"FS Driver", L"Own Process", L"Share Process",
|
||||
L"Own Interactive Process", L"Share Interactive Process" };
|
||||
WCHAR *serviceStartTypeItems[] = { L"Disabled", L"Boot Start", L"System Start",
|
||||
L"Auto Start", L"Demand Start" };
|
||||
WCHAR *serviceErrorControlItems[] = { L"Ignore", L"Normal", L"Severe", L"Critical" };
|
||||
LPPROPSHEETPAGE propSheetPage = (LPPROPSHEETPAGE)lParam;
|
||||
PSERVICE_PROPERTIES_CONTEXT context = (PSERVICE_PROPERTIES_CONTEXT)propSheetPage->lParam;
|
||||
PPH_SERVICE_ITEM serviceItem = context->ServiceItem;
|
||||
@@ -152,12 +135,12 @@ INT_PTR CALLBACK PhpServiceGeneralDlgProc(
|
||||
|
||||
SetProp(hwndDlg, L"Context", (HANDLE)context);
|
||||
|
||||
PhpAddComboBoxItems(GetDlgItem(hwndDlg, IDC_TYPE), serviceTypeItems,
|
||||
sizeof(serviceTypeItems) / sizeof(WCHAR *));
|
||||
PhpAddComboBoxItems(GetDlgItem(hwndDlg, IDC_STARTTYPE), serviceStartTypeItems,
|
||||
sizeof(serviceStartTypeItems) / sizeof(WCHAR *));
|
||||
PhpAddComboBoxItems(GetDlgItem(hwndDlg, IDC_ERRORCONTROL), serviceErrorControlItems,
|
||||
sizeof(serviceErrorControlItems) / sizeof(WCHAR *));
|
||||
PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_TYPE), PhServiceTypeStrings,
|
||||
sizeof(PhServiceTypeStrings) / sizeof(WCHAR *));
|
||||
PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_STARTTYPE), PhServiceStartTypeStrings,
|
||||
sizeof(PhServiceStartTypeStrings) / sizeof(WCHAR *));
|
||||
PhAddComboBoxStrings(GetDlgItem(hwndDlg, IDC_ERRORCONTROL), PhServiceErrorControlStrings,
|
||||
sizeof(PhServiceErrorControlStrings) / sizeof(WCHAR *));
|
||||
|
||||
SetDlgItemText(hwndDlg, IDC_DESCRIPTION, serviceItem->DisplayName->Buffer);
|
||||
ComboBox_SelectString(GetDlgItem(hwndDlg, IDC_TYPE), -1,
|
||||
|
||||
@@ -326,6 +326,18 @@ PPH_STRING PhGetWindowText(
|
||||
}
|
||||
}
|
||||
|
||||
VOID PhAddComboBoxStrings(
|
||||
__in HWND hWnd,
|
||||
__in PWSTR *Strings,
|
||||
__in ULONG NumberOfStrings
|
||||
)
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
for (i = 0; i < NumberOfStrings; i++)
|
||||
ComboBox_AddString(hWnd, Strings[i]);
|
||||
}
|
||||
|
||||
PPH_STRING PhGetComboBoxString(
|
||||
__in HWND hwnd,
|
||||
__in INT Index
|
||||
|
||||
@@ -1366,6 +1366,12 @@ VOID PhSymbolProviderSetSearchPath(
|
||||
|
||||
// svcsup
|
||||
|
||||
#ifndef SVCSUP_PRIVATE
|
||||
extern WCHAR *PhServiceTypeStrings[6];
|
||||
extern WCHAR *PhServiceStartTypeStrings[5];
|
||||
extern WCHAR *PhServiceErrorControlStrings[4];
|
||||
#endif
|
||||
|
||||
PVOID PhEnumServices(
|
||||
__in SC_HANDLE ScManagerHandle,
|
||||
__in_opt ULONG Type,
|
||||
|
||||
@@ -313,6 +313,12 @@ PPH_STRING PhGetWindowText(
|
||||
__in HWND hwnd
|
||||
);
|
||||
|
||||
VOID PhAddComboBoxStrings(
|
||||
__in HWND hWnd,
|
||||
__in PWSTR *Strings,
|
||||
__in ULONG NumberOfStrings
|
||||
);
|
||||
|
||||
PPH_STRING PhGetComboBoxString(
|
||||
__in HWND hwnd,
|
||||
__in INT Index
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
* along with Process Hacker. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define SVCSUP_PRIVATE
|
||||
#include <ph.h>
|
||||
|
||||
#define SIP(String, Integer) { (String), (PVOID)(Integer) }
|
||||
@@ -61,6 +62,12 @@ static PH_KEY_VALUE_PAIR PhpServiceErrorControlPairs[] =
|
||||
SIP(L"Critical", SERVICE_ERROR_CRITICAL)
|
||||
};
|
||||
|
||||
WCHAR *PhServiceTypeStrings[6] = { L"Driver", L"FS Driver", L"Own Process", L"Share Process",
|
||||
L"Own Interactive Process", L"Share Interactive Process" };
|
||||
WCHAR *PhServiceStartTypeStrings[5] = { L"Disabled", L"Boot Start", L"System Start",
|
||||
L"Auto Start", L"Demand Start" };
|
||||
WCHAR *PhServiceErrorControlStrings[4] = { L"Ignore", L"Normal", L"Severe", L"Critical" };
|
||||
|
||||
PVOID PhEnumServices(
|
||||
__in SC_HANDLE ScManagerHandle,
|
||||
__in_opt ULONG Type,
|
||||
@@ -330,14 +337,17 @@ PPH_STRING PhGetServiceNameFromTag(
|
||||
__in PVOID ServiceTag
|
||||
)
|
||||
{
|
||||
static _I_QueryTagInformation I_QueryTagInformation = NULL;
|
||||
PPH_STRING serviceName = NULL;
|
||||
_I_QueryTagInformation I_QueryTagInformation;
|
||||
SC_SERVICE_NAME_FROM_TAG_QUERY query;
|
||||
|
||||
I_QueryTagInformation = PhGetProcAddress(L"advapi32.dll", "I_QueryTagInformation");
|
||||
|
||||
if (!I_QueryTagInformation)
|
||||
return NULL;
|
||||
{
|
||||
I_QueryTagInformation = PhGetProcAddress(L"advapi32.dll", "I_QueryTagInformation");
|
||||
|
||||
if (!I_QueryTagInformation)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
query.ProcessId = (ULONG)ProcessId;
|
||||
query.ServiceTag = (ULONG)ServiceTag;
|
||||
|
||||
Reference in New Issue
Block a user