Files
dmex b02427417c PH1.x: fixed build
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5614 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2014-02-25 23:14:38 +00:00

93 lines
3.2 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ProcessHacker.Common;
using ProcessHacker.Native.Api;
using ProcessHacker.Native.Objects;
using ProcessHacker.Native.Security;
namespace ProcessHacker
{
public partial class CreateServiceWindow : Form
{
public CreateServiceWindow()
{
InitializeComponent();
this.AddEscapeToClose();
this.SetTopMost();
Utils.Fill(comboErrorControl, typeof(ServiceErrorControl));
Utils.Fill(comboStartType, typeof(ServiceStartType));
Utils.Fill(comboType, typeof(ServiceType));
comboType.Items.Add("Win32OwnProcess, InteractiveProcess");
comboErrorControl.SelectedItem = "Ignore";
comboStartType.SelectedItem = "DemandStart";
comboType.SelectedItem = "Win32OwnProcess";
}
private void CreateServiceWindow_Load(object sender, EventArgs e)
{
textName.Select();
}
private void buttonBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Executable Files (*.exe)|*.exe|All Files (*.*)|*.*";
ofd.FileName = textBinaryPath.Text;
if (ofd.ShowDialog() == DialogResult.OK)
textBinaryPath.Text = ofd.FileName;
}
private void buttonOK_Click(object sender, EventArgs e)
{
try
{
using (var scmhandle = new ServiceManagerHandle(ScManagerAccess.CreateService))
{
ServiceType serviceType;
if (comboType.SelectedItem.ToString() == "Win32OwnProcess, InteractiveProcess")
serviceType = ServiceType.Win32OwnProcess |
ServiceType.InteractiveProcess;
else
serviceType = (ServiceType)Enum.Parse(typeof(ServiceType), comboType.SelectedItem.ToString());
var startType = (ServiceStartType)
Enum.Parse(typeof(ServiceStartType), comboStartType.SelectedItem.ToString());
var errorControl = (ServiceErrorControl)
Enum.Parse(typeof(ServiceErrorControl), comboErrorControl.SelectedItem.ToString());
scmhandle.CreateService(
textName.Text,
textDisplayName.Text,
serviceType,
startType,
errorControl,
textBinaryPath.Text,
null,
null,
null
).Dispose();
this.Close();
}
}
catch (Exception ex)
{
PhUtils.ShowException("Unable to create the service", ex);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}