commit b6c092d508ee5f1262bc2d431f63d9891a8b69d2 Author: Eugen Höglinger Date: Thu Feb 27 14:31:19 2020 +0100 Projekt neu angelegt. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a5f80a --- /dev/null +++ b/.gitignore @@ -0,0 +1,32 @@ + +#Ignore thumbnails created by Windows +Thumbs.db +#Ignore files built by Visual Studio +*.obj +*.exe +*.pdb +*.user +*.aps +*.pch +*.vspscc +*_i.c +*_p.c +*.ncb +*.suo +*.tlb +*.tlh +*.bak +*.cache +*.ilk +*.log +[Bb]in +[Dd]ebug*/ +*.lib +*.sbr +obj/ +[Rr]elease*/ +_ReSharper*/ +[Tt]est[Rr]esult* +.vs/ +#Nuget packages folder +packages/ diff --git a/Daten/Test.txt b/Daten/Test.txt new file mode 100644 index 0000000..9652376 --- /dev/null +++ b/Daten/Test.txt @@ -0,0 +1 @@ +Das ist ein Test. \ No newline at end of file diff --git a/StartStopExtProgram.sln b/StartStopExtProgram.sln new file mode 100644 index 0000000..3cca787 --- /dev/null +++ b/StartStopExtProgram.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.572 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StartStopExtProgram", "StartStopExtProgram\StartStopExtProgram.csproj", "{D9FA7EAE-2785-4856-BD44-1320C7E3BD39}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D9FA7EAE-2785-4856-BD44-1320C7E3BD39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D9FA7EAE-2785-4856-BD44-1320C7E3BD39}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D9FA7EAE-2785-4856-BD44-1320C7E3BD39}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D9FA7EAE-2785-4856-BD44-1320C7E3BD39}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {76C786AB-666C-4C58-B65A-1FD47B019205} + EndGlobalSection +EndGlobal diff --git a/StartStopExtProgram/Form1.Designer.cs b/StartStopExtProgram/Form1.Designer.cs new file mode 100644 index 0000000..de126a5 --- /dev/null +++ b/StartStopExtProgram/Form1.Designer.cs @@ -0,0 +1,73 @@ +namespace Eugen.ESystem +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Vom Windows Form-Designer generierter Code + + /// + /// Erforderliche Methode für die Designerunterstützung. + /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. + /// + private void InitializeComponent() + { + this.buttonStartStop = new System.Windows.Forms.Button(); + this.labelStatus = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonStartStop + // + this.buttonStartStop.Anchor = System.Windows.Forms.AnchorStyles.Bottom; + this.buttonStartStop.Location = new System.Drawing.Point(135, 121); + this.buttonStartStop.Name = "buttonStartStop"; + this.buttonStartStop.Size = new System.Drawing.Size(75, 23); + this.buttonStartStop.TabIndex = 2; + this.buttonStartStop.Text = "Start / Stop"; + this.buttonStartStop.UseVisualStyleBackColor = true; + this.buttonStartStop.Click += new System.EventHandler(this.buttonStartStop_Click); + // + // labelStatus + // + this.labelStatus.AutoSize = true; + this.labelStatus.Location = new System.Drawing.Point(12, 54); + this.labelStatus.Name = "labelStatus"; + this.labelStatus.Size = new System.Drawing.Size(326, 13); + this.labelStatus.TabIndex = 0; + this.labelStatus.Text = "Start / Stop drücken um das Programm zu Starten oder zu Beenden"; + // + // Form1 + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(345, 156); + this.Controls.Add(this.labelStatus); + this.Controls.Add(this.buttonStartStop); + this.Name = "Form1"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button buttonStartStop; + private System.Windows.Forms.Label labelStatus; + } +} \ No newline at end of file diff --git a/StartStopExtProgram/Form1.cs b/StartStopExtProgram/Form1.cs new file mode 100644 index 0000000..c7c091c --- /dev/null +++ b/StartStopExtProgram/Form1.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Eugen.ESystem +{ + public partial class Form1 : Form + { + #region Version und Copyright + // Version und Copyright + string programName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen + string programVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); + string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + string icon = Application.StartupPath + "\\Info.bmp"; + //Assembly Datum und Zeit + static DateTime value = AssemblyDateTime(); + string date = value.ToShortDateString(); + string time = value.ToLongTimeString(); + private static DateTime AssemblyDateTime() + { + var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; + var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); + //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) + return buildDateTime; + } + #endregion + + #region Programm-Info + /// + /// Contains the name of the programName file + /// + public static string ProgramName { set; get; } + + /// + /// Contains the version of the programName file + /// + public static string ProgramVersion { set; get; } + + /// + /// Contains the copyright notice + /// + public static string Copyright { set; get; } + + private void SetProgramInfo() + { + //Name, Version und Copyright setzen + ProgramName = programName; + ProgramVersion = programVersion; + Copyright = copyright; + } + #endregion + + public Form1() + { + SetProgramInfo(); //Name, Version und Copyright setzen + InitializeComponent(); + } + + private void buttonStartStop_Click(object sender, EventArgs e) + { + string programPath = @"C:\Windows"; //Programmpfad + string programName = "Notepad.exe"; //Programm Name + string arg = @"H:\Programmieren\Visual Studio 2017\Projekte\_DLL\StartStopExtProgram\Daten\Test.txt"; //Argument das übergeben wird + bool winStyleMinimized = false; //Anzeige des Programmfensters. false=Sichtbar, true=Minimiert + + //Nachfolgend die möglichen Aufrufvarianten + try + { + //var startStop = new StartStopExtProgram(String.Concat(programPath, "\\", programName)); + //var startStop = new StartStopExtProgram(String.Concat(programPath, "\\", programName), winStyleMinimized); + //var startStop = new StartStopExtProgram(String.Concat(programPath, "\\", programName), arg, winStyleMinimized); + var startStop = new StartStopExtProgram(programPath, programName, arg, winStyleMinimized); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } + } +} diff --git a/StartStopExtProgram/Form1.resx b/StartStopExtProgram/Form1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/StartStopExtProgram/Form1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StartStopExtProgram/Language.Designer.cs b/StartStopExtProgram/Language.Designer.cs new file mode 100644 index 0000000..54ec609 --- /dev/null +++ b/StartStopExtProgram/Language.Designer.cs @@ -0,0 +1,108 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion:4.0.30319.42000 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Eugen.ESystem { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Language { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Language() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Eugen.ESystem.Language", typeof(Language).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Das angegebene Programm wurde nicht gefunden! ähnelt. + /// + internal static string message001 { + get { + return ResourceManager.GetString("message001", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Der angegebene Programmname wurde nicht gefunden! ähnelt. + /// + internal static string message002 { + get { + return ResourceManager.GetString("message002", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Der angegebene Programmpfad wurde nicht gefunden! ähnelt. + /// + internal static string message003 { + get { + return ResourceManager.GetString("message003", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Der Prozessname konnte nicht generiert werden! ähnelt. + /// + internal static string message004 { + get { + return ResourceManager.GetString("message004", resourceCulture); + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Programm konnte nicht gestartet werden! ähnelt. + /// + internal static string message005 { + get { + return ResourceManager.GetString("message005", resourceCulture); + } + } + } +} diff --git a/StartStopExtProgram/Language.de.Designer.cs b/StartStopExtProgram/Language.de.Designer.cs new file mode 100644 index 0000000..e69de29 diff --git a/StartStopExtProgram/Language.de.resx b/StartStopExtProgram/Language.de.resx new file mode 100644 index 0000000..965d418 --- /dev/null +++ b/StartStopExtProgram/Language.de.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Das angegebene Programm wurde nicht gefunden! + + + Der angegebene Programmname wurde nicht gefunden! + + + Der angegebene Programmpfad wurde nicht gefunden! + + + Der Prozessname konnte nicht generiert werden! + + + Programm konnte nicht gestartet werden! + + \ No newline at end of file diff --git a/StartStopExtProgram/Language.en.resx b/StartStopExtProgram/Language.en.resx new file mode 100644 index 0000000..10ce189 --- /dev/null +++ b/StartStopExtProgram/Language.en.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The specified program was not found! + + + The specified program name was not found! + + + The specified program path was not found! + + + The process name could not be generated! + + + Program could not be started! + + \ No newline at end of file diff --git a/StartStopExtProgram/Language.resx b/StartStopExtProgram/Language.resx new file mode 100644 index 0000000..965d418 --- /dev/null +++ b/StartStopExtProgram/Language.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Das angegebene Programm wurde nicht gefunden! + + + Der angegebene Programmname wurde nicht gefunden! + + + Der angegebene Programmpfad wurde nicht gefunden! + + + Der Prozessname konnte nicht generiert werden! + + + Programm konnte nicht gestartet werden! + + \ No newline at end of file diff --git a/StartStopExtProgram/Program.cs b/StartStopExtProgram/Program.cs new file mode 100644 index 0000000..957ae98 --- /dev/null +++ b/StartStopExtProgram/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Eugen.ESystem +{ + static class Program + { + /// + /// Der Haupteinstiegspunkt für die Anwendung. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/StartStopExtProgram/Properties/AssemblyInfo.cs b/StartStopExtProgram/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1b8bc20 --- /dev/null +++ b/StartStopExtProgram/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("StartStopExtProgram")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StartStopExtProgram")] +[assembly: AssemblyCopyright("Copyright © 2019 by Eugen Höglinger")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("d9fa7eae-2785-4856-bd44-1320c7e3bd39")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.*")] +//[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/StartStopExtProgram/StartStopExtProgram.cs b/StartStopExtProgram/StartStopExtProgram.cs new file mode 100644 index 0000000..b073470 --- /dev/null +++ b/StartStopExtProgram/StartStopExtProgram.cs @@ -0,0 +1,322 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Resources; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Eugen.ESystem +{ + public class StartStopExtProgram + { + /// + /// Starts or stops an external program. + /// + /// A valid program name with path and extension. + public StartStopExtProgram(string program) + { + SetBaseValues(program); + StartStop(String.Concat(ProgramPath, "\\", Program), Arg, WinStyleMinimized, ProcessName); + } + + /// + /// Starts or stops an external program in declared window style. + /// + /// A valid program name with path and extension. + /// Window style: false=visible, true=minimized. + public StartStopExtProgram(string program, bool winStyleMinimized) + { + SetBaseValues(program, winStyleMinimized); + StartStop(String.Concat(ProgramPath, "\\", Program), Arg, WinStyleMinimized, ProcessName); + } + + /// + /// Starts or stops an external program in declared window style and transfer parameter. + /// + /// A valid program name with path and extension. + /// A valid transfer parameter. + /// Window style: false=visible, true=minimized. + public StartStopExtProgram(string program, string arg, bool winStyleMinimized) + { + SetBaseValues(program, arg, winStyleMinimized); + StartStop(String.Concat(ProgramPath, "\\", Program), Arg, WinStyleMinimized, ProcessName); + } + + /// + /// Starts or stops an external program in declared window style and transfer parameter. + /// + /// A valid program path. + /// A valid program name with extension. + /// A valid transfer parameter. + /// Window style: false=visible, true=minimized. + public StartStopExtProgram(string programPath, string programName, string arg, bool winStyleMinimized) + { + SetBaseValues(programPath, programName, arg, winStyleMinimized); + StartStop(String.Concat(ProgramPath, "\\", Program), Arg, WinStyleMinimized, ProcessName); + } + + protected string ProgramPath { set; get; } + protected string Program { set; get; } + protected string Arg { set; get; } + protected bool WinStyleMinimized { set; get; } + protected string ProcessName { set; get; } + + private void SetBaseValues(string program) + { + if (File.Exists(program)) + { + Program = Path.GetFileName(program); + ProgramPath = Path.GetDirectoryName(program); + } + else + { + throw new NoValidProgramNameException(Language.message001); + } + + Arg = ""; + WinStyleMinimized = false; + + ProcessName = SetProcessName(program); + } + + private void SetBaseValues(string program, bool winStyleMinimized) + { + if (File.Exists(program)) + { + Program = Path.GetFileName(program); + ProgramPath = Path.GetDirectoryName(program); + } + else + { + throw new NoValidProgramNameException(Language.message001); + } + + Arg = ""; + WinStyleMinimized = winStyleMinimized; + + ProcessName = SetProcessName(program); + } + + private void SetBaseValues(string program, string arg, bool winStyleMinimized) + { + if (File.Exists(program)) + { + Program = Path.GetFileName(program); + ProgramPath = Path.GetDirectoryName(program); + } + else + { + throw new NoValidProgramNameException(Language.message001); + } + + Arg = arg; + WinStyleMinimized = winStyleMinimized; + + ProcessName = SetProcessName(program); + } + + private void SetBaseValues(string programPath, string programName, string arg, bool winStyleMinimized) + { + if (Directory.Exists(programPath)) + { + ProgramPath = programPath; + } + else + { + throw new NoValidFolderStructureException(Language.message003); + } + + if (File.Exists(String.Concat(programPath, "\\", programName))) + { + Program = programName; + } + else + { + throw new NoValidProgramNameException(Language.message002); + } + + Arg = arg; + WinStyleMinimized = winStyleMinimized; + + ProcessName = SetProcessName(programName); + } + + private string SetProcessName(string program) + { + if (!String.IsNullOrEmpty(program)) + { + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + sb.Append(program.Substring(0, 1).ToUpper() + program.Substring(1)); + return Path.GetFileNameWithoutExtension(sb.ToString()); + } + else + { + throw new UnableToGenerateProcessNameException(Language.message002); + } + } + + private void StartStop(string program, string arg, bool winStyle, string processName) + { + if (!CheckProcessIsRun(processName)) + { + Start(program, arg, winStyle); + } + else + { + Stop(program); + } + } + + private static bool CheckProcessIsRun(string processName) + { + //Prüfen ob der Prozess läuft + return (Process.GetProcessesByName(processName).Length > 0); + } + + private void Start(string program, string arg, bool winStyle) + { + try + { + ProcessStartInfo startProgram = new ProcessStartInfo(program); + startProgram.Arguments = arg; + if (winStyle) + { + startProgram.WindowStyle = ProcessWindowStyle.Minimized; + } + Process.Start(startProgram); + } + catch (Exception) + { + throw new UnableToRunProgramException(Language.message005); + } + } + + private void Stop(string program) + { + try + { + string process = program.Remove(0, program.LastIndexOf(@"\") + 1); + process = process.Remove(process.Length - 4); + + Process[] close = Process.GetProcessesByName(process); + close[0].CloseMainWindow(); + close[0].Kill(); + } + catch (Exception ex) + { + throw new UnableToStopProgramException("Programm konnte nicht beendet werden!\n\n" + ex); + } + } + } + + #region Exceptions + class NoValidFolderStructureException : ApplicationException + { + public NoValidFolderStructureException() + { + } + + public NoValidFolderStructureException(string message) + : base(message) + { + } + + public NoValidFolderStructureException(string message, Exception inner) + : base(message, inner) + { + } + } + + class NoValidProgramNameException : ApplicationException + { + public NoValidProgramNameException() + { + } + + public NoValidProgramNameException(string message) + : base(message) + { + } + + public NoValidProgramNameException(string message, Exception inner) + : base(message, inner) + { + } + } + + class UnknownErrorException : ApplicationException + { + public UnknownErrorException() + { + } + + public UnknownErrorException(string message) + : base(message) + { + } + + public UnknownErrorException(string message, Exception inner) + : base(message, inner) + { + } + } + + class UnableToRunProgramException : ApplicationException + { + public UnableToRunProgramException() + { + } + + public UnableToRunProgramException(string message) + : base(message) + { + } + + public UnableToRunProgramException(string message, Exception inner) + : base(message, inner) + { + } + } + + class UnableToStopProgramException : ApplicationException + { + public UnableToStopProgramException() + { + } + + public UnableToStopProgramException(string message) + : base(message) + { + } + + public UnableToStopProgramException(string message, Exception inner) + : base(message, inner) + { + } + } + + class UnableToGenerateProcessNameException : ApplicationException + { + public UnableToGenerateProcessNameException() + { + } + + public UnableToGenerateProcessNameException(string message) + : base(message) + { + } + + public UnableToGenerateProcessNameException(string message, Exception inner) + : base(message, inner) + { + } + } + #endregion +} diff --git a/StartStopExtProgram/StartStopExtProgram.csproj b/StartStopExtProgram/StartStopExtProgram.csproj new file mode 100644 index 0000000..14a7e59 --- /dev/null +++ b/StartStopExtProgram/StartStopExtProgram.csproj @@ -0,0 +1,84 @@ + + + + + Debug + AnyCPU + {D9FA7EAE-2785-4856-BD44-1320C7E3BD39} + WinExe + Properties + Eugen.ESystem + StartStopExtProgram + v4.6.1 + 512 + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + True + True + Language.resx + + + True + True + Language.de.resx + + + + + + + + Form1.cs + + + + ResXFileCodeGenerator + Language.Designer.cs + + + ResXFileCodeGenerator + Language.de.Designer.cs + + + + \ No newline at end of file