diff --git a/2.x/trunk/ProcessHacker/ProcessHacker.vcproj b/2.x/trunk/ProcessHacker/ProcessHacker.vcproj
index 2cb9b64df..61b3f2262 100644
--- a/2.x/trunk/ProcessHacker/ProcessHacker.vcproj
+++ b/2.x/trunk/ProcessHacker/ProcessHacker.vcproj
@@ -516,6 +516,10 @@
RelativePath=".\settings.c"
>
+
+
diff --git a/2.x/trunk/ProcessHacker/actions.c b/2.x/trunk/ProcessHacker/actions.c
index 61f7c88cb..b3d40605d 100644
--- a/2.x/trunk/ProcessHacker/actions.c
+++ b/2.x/trunk/ProcessHacker/actions.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)
{
diff --git a/2.x/trunk/ProcessHacker/include/phapp.h b/2.x/trunk/ProcessHacker/include/phapp.h
index 66a7658ea..ea4092742 100644
--- a/2.x/trunk/ProcessHacker/include/phapp.h
+++ b/2.x/trunk/ProcessHacker/include/phapp.h
@@ -821,6 +821,12 @@ VOID PhShowSessionProperties(
__in ULONG SessionId
);
+// srvcr
+
+VOID PhShowCreateServiceDialog(
+ __in HWND ParentWindowHandle
+ );
+
// srvprp
VOID PhShowServiceProperties(
diff --git a/2.x/trunk/ProcessHacker/mainwnd.c b/2.x/trunk/ProcessHacker/mainwnd.c
index e5ef1eeec..3a66a2f89 100644
--- a/2.x/trunk/ProcessHacker/mainwnd.c
+++ b/2.x/trunk/ProcessHacker/mainwnd.c
@@ -638,6 +638,11 @@ LRESULT CALLBACK PhMainWndProc(
);
}
break;
+ case ID_TOOLS_CREATESERVICE:
+ {
+ PhShowCreateServiceDialog(hWnd);
+ }
+ break;
case ID_TOOLS_HIDDENPROCESSES:
{
PhShowHiddenProcessesDialog();
diff --git a/2.x/trunk/ProcessHacker/srvcr.c b/2.x/trunk/ProcessHacker/srvcr.c
new file mode 100644
index 000000000..3701d4e98
--- /dev/null
+++ b/2.x/trunk/ProcessHacker/srvcr.c
@@ -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 .
+ */
+
+#include
+#include
+
+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;
+}
diff --git a/2.x/trunk/ProcessHacker/srvprp.c b/2.x/trunk/ProcessHacker/srvprp.c
index da0109dd3..a414e5b0c 100644
--- a/2.x/trunk/ProcessHacker/srvprp.c
+++ b/2.x/trunk/ProcessHacker/srvprp.c
@@ -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,
diff --git a/2.x/trunk/phlib/guisup.c b/2.x/trunk/phlib/guisup.c
index 5fa459ee4..f161f83ad 100644
--- a/2.x/trunk/phlib/guisup.c
+++ b/2.x/trunk/phlib/guisup.c
@@ -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
diff --git a/2.x/trunk/phlib/include/ph.h b/2.x/trunk/phlib/include/ph.h
index 0a5d3d8b7..02e44decf 100644
--- a/2.x/trunk/phlib/include/ph.h
+++ b/2.x/trunk/phlib/include/ph.h
@@ -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,
diff --git a/2.x/trunk/phlib/include/phgui.h b/2.x/trunk/phlib/include/phgui.h
index 26eb4927f..21d0ba931 100644
--- a/2.x/trunk/phlib/include/phgui.h
+++ b/2.x/trunk/phlib/include/phgui.h
@@ -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
diff --git a/2.x/trunk/phlib/svcsup.c b/2.x/trunk/phlib/svcsup.c
index e4d71bc2a..ceb8961ff 100644
--- a/2.x/trunk/phlib/svcsup.c
+++ b/2.x/trunk/phlib/svcsup.c
@@ -20,6 +20,7 @@
* along with Process Hacker. If not, see .
*/
+#define SVCSUP_PRIVATE
#include
#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;