From 959474e42ec96dc1058d08fcfe9144f3ae62a764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eugen=20H=C3=B6glinger?= Date: Thu, 27 Feb 2020 14:25:04 +0100 Subject: [PATCH] Projekt neu angelegt. --- .gitignore | 32 ++ Daten/Test.txt | 1 + StartStopExtProgram.sln | 31 ++ StartStopExtProgram/Language.Designer.cs | 108 +++++ StartStopExtProgram/Language.de.Designer.cs | 0 StartStopExtProgram/Language.de.resx | 135 ++++++ StartStopExtProgram/Language.en.resx | 135 ++++++ StartStopExtProgram/Language.resx | 135 ++++++ .../Properties/AssemblyInfo.cs | 36 ++ StartStopExtProgram/StartStopExtProgram.cs | 385 ++++++++++++++++++ .../StartStopExtProgram.csproj | 69 ++++ Test_StartStopExtProgram/App.config | 6 + Test_StartStopExtProgram/Form1.Designer.cs | 74 ++++ Test_StartStopExtProgram/Form1.cs | 93 +++++ Test_StartStopExtProgram/Form1.en.resx | 133 ++++++ Test_StartStopExtProgram/Form1.resx | 222 ++++++++++ Test_StartStopExtProgram/Program.cs | 22 + .../Properties/AssemblyInfo.cs | 36 ++ .../Properties/Resources.Designer.cs | 71 ++++ .../Properties/Resources.resx | 117 ++++++ .../Properties/Settings.Designer.cs | 30 ++ .../Properties/Settings.settings | 7 + .../Test_StartStopExtProgram.csproj | 92 +++++ 23 files changed, 1970 insertions(+) create mode 100644 .gitignore create mode 100644 Daten/Test.txt create mode 100644 StartStopExtProgram.sln create mode 100644 StartStopExtProgram/Language.Designer.cs create mode 100644 StartStopExtProgram/Language.de.Designer.cs create mode 100644 StartStopExtProgram/Language.de.resx create mode 100644 StartStopExtProgram/Language.en.resx create mode 100644 StartStopExtProgram/Language.resx create mode 100644 StartStopExtProgram/Properties/AssemblyInfo.cs create mode 100644 StartStopExtProgram/StartStopExtProgram.cs create mode 100644 StartStopExtProgram/StartStopExtProgram.csproj create mode 100644 Test_StartStopExtProgram/App.config create mode 100644 Test_StartStopExtProgram/Form1.Designer.cs create mode 100644 Test_StartStopExtProgram/Form1.cs create mode 100644 Test_StartStopExtProgram/Form1.en.resx create mode 100644 Test_StartStopExtProgram/Form1.resx create mode 100644 Test_StartStopExtProgram/Program.cs create mode 100644 Test_StartStopExtProgram/Properties/AssemblyInfo.cs create mode 100644 Test_StartStopExtProgram/Properties/Resources.Designer.cs create mode 100644 Test_StartStopExtProgram/Properties/Resources.resx create mode 100644 Test_StartStopExtProgram/Properties/Settings.Designer.cs create mode 100644 Test_StartStopExtProgram/Properties/Settings.settings create mode 100644 Test_StartStopExtProgram/Test_StartStopExtProgram.csproj 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..9dd70bc --- /dev/null +++ b/StartStopExtProgram.sln @@ -0,0 +1,31 @@ + +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 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_StartStopExtProgram", "Test_StartStopExtProgram\Test_StartStopExtProgram.csproj", "{A8D979D5-120D-4649-9E74-FA646A3E57D2}" +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 + {A8D979D5-120D-4649-9E74-FA646A3E57D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8D979D5-120D-4649-9E74-FA646A3E57D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8D979D5-120D-4649-9E74-FA646A3E57D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8D979D5-120D-4649-9E74-FA646A3E57D2}.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/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/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..dd9908d --- /dev/null +++ b/StartStopExtProgram/StartStopExtProgram.cs @@ -0,0 +1,385 @@ +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 + { + #region Version und Copyright + // Version und Copyright + string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen + string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); + static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); + string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + //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 DLL-Info + /// + /// Contains the name of the dll file. + /// + public static string DllName { private set; get; } + + /// + /// Contains the version of the dll file. + /// + public static string DllVersion { private set; get; } + + /// + /// Contains the copyright notice. + /// + public static string Copyright { private set; get; } + + /// + /// Contains the name-, version- and copyright-information of the dll file. + /// + public static string[] DllInfo { private set; get; } + + private void SetDllInfo() + { + //Name, Version und Copyright setzen + DllName = dllName; + DllVersion = dllVersion; + Copyright = this.copyright; + + string[] dllInfo = new string[3]; + dllInfo[0] = dllName; + dllInfo[1] = dllVersion; + dllInfo[2] = this.copyright; + DllInfo = dllInfo; + } + #endregion + + /// + /// Starts or stops an external program. + /// + /// A valid program name with path and extension. + public StartStopExtProgram(string program) + { + SetDllInfo(); //Name, Version und Copyright der DLL setzen + + 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) + { + SetDllInfo(); //Name, Version und Copyright der DLL setzen + + 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) + { + SetDllInfo(); //Name, Version und Copyright der DLL setzen + + 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) + { + SetDllInfo(); //Name, Version und Copyright der DLL setzen + + 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..758d239 --- /dev/null +++ b/StartStopExtProgram/StartStopExtProgram.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {D9FA7EAE-2785-4856-BD44-1320C7E3BD39} + Library + 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 + + + + + + + + + + + + + + True + True + Language.resx + + + True + True + Language.de.resx + + + + + + + + ResXFileCodeGenerator + Language.Designer.cs + + + ResXFileCodeGenerator + Language.de.Designer.cs + + + + \ No newline at end of file diff --git a/Test_StartStopExtProgram/App.config b/Test_StartStopExtProgram/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/Test_StartStopExtProgram/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Test_StartStopExtProgram/Form1.Designer.cs b/Test_StartStopExtProgram/Form1.Designer.cs new file mode 100644 index 0000000..5057406 --- /dev/null +++ b/Test_StartStopExtProgram/Form1.Designer.cs @@ -0,0 +1,74 @@ +namespace Test_StartStopExtProgram +{ + partial class Form1 + { + /// + /// Erforderliche Designervariable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Verwendete Ressourcen bereinigen. + /// + /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + this.buttonStartStop = new System.Windows.Forms.Button(); + this.labelDllInfo = new System.Windows.Forms.Label(); + this.labelStatus = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // buttonStartStop + // + resources.ApplyResources(this.buttonStartStop, "buttonStartStop"); + this.buttonStartStop.Name = "buttonStartStop"; + this.buttonStartStop.UseVisualStyleBackColor = true; + this.buttonStartStop.Click += new System.EventHandler(this.buttonStartStop_Click); + // + // labelDllInfo + // + resources.ApplyResources(this.labelDllInfo, "labelDllInfo"); + this.labelDllInfo.Name = "labelDllInfo"; + // + // labelStatus + // + resources.ApplyResources(this.labelStatus, "labelStatus"); + this.labelStatus.Name = "labelStatus"; + // + // Form1 + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.labelStatus); + this.Controls.Add(this.labelDllInfo); + 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 labelDllInfo; + private System.Windows.Forms.Label labelStatus; + } +} + diff --git a/Test_StartStopExtProgram/Form1.cs b/Test_StartStopExtProgram/Form1.cs new file mode 100644 index 0000000..c497a76 --- /dev/null +++ b/Test_StartStopExtProgram/Form1.cs @@ -0,0 +1,93 @@ +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; +using Eugen.ESystem; + +namespace Test_StartStopExtProgram +{ + 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); + } + + //Ausgabe der DLL Informationen + labelDllInfo.Text = String.Concat(StartStopExtProgram.DllName, "\r\n", StartStopExtProgram.DllVersion, "\r\n", StartStopExtProgram.Copyright); + } + } +} diff --git a/Test_StartStopExtProgram/Form1.en.resx b/Test_StartStopExtProgram/Form1.en.resx new file mode 100644 index 0000000..10c8dc7 --- /dev/null +++ b/Test_StartStopExtProgram/Form1.en.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + 70, 120 + + + 223, 13 + + + Press Start / Stop to start or stop the program. + + + 249, 155 + + \ No newline at end of file diff --git a/Test_StartStopExtProgram/Form1.resx b/Test_StartStopExtProgram/Form1.resx new file mode 100644 index 0000000..b6c680d --- /dev/null +++ b/Test_StartStopExtProgram/Form1.resx @@ -0,0 +1,222 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + $this + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + 6, 13 + + + + Bottom + + + + 1 + + + 13, 13 + + + labelStatus + + + 16, 13 + + + $this + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Form1 + + + $this + + + True + + + 350, 155 + + + 0 + + + 327, 13 + + + System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 13, 88 + + + 1 + + + 109, 23 + + + Start / Stop drücken um das Programm zu starten oder zu Beenden. + + + 0 + + + Start / Stop + + + 2 + + + 121, 120 + + + labelDllInfo + + + True + + + ... + + + Form1 + + + 2 + + + buttonStartStop + + + True + + \ No newline at end of file diff --git a/Test_StartStopExtProgram/Program.cs b/Test_StartStopExtProgram/Program.cs new file mode 100644 index 0000000..61264a4 --- /dev/null +++ b/Test_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 Test_StartStopExtProgram +{ + 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/Test_StartStopExtProgram/Properties/AssemblyInfo.cs b/Test_StartStopExtProgram/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..69cb15b --- /dev/null +++ b/Test_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("Test_StartStopExtProgram")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Test_StartStopExtProgram")] +[assembly: AssemblyCopyright("Copyright © 2019 ")] +[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("a8d979d5-120d-4649-9e74-fa646a3e57d2")] + +// 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, +// übernehmen, indem Sie "*" eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Test_StartStopExtProgram/Properties/Resources.Designer.cs b/Test_StartStopExtProgram/Properties/Resources.Designer.cs new file mode 100644 index 0000000..d0bcd4b --- /dev/null +++ b/Test_StartStopExtProgram/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion: 4.0.30319.42000 +// +// Änderungen an dieser Datei können fehlerhaftes Verhalten verursachen und gehen verloren, wenn +// der Code neu generiert wird. +// +//------------------------------------------------------------------------------ + +namespace Test_StartStopExtProgram.Properties +{ + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder-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 Option /str erneut aus, oder erstellen Sie Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 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 ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Test_StartStopExtProgram.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenlookups, 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; + } + } + } +} diff --git a/Test_StartStopExtProgram/Properties/Resources.resx b/Test_StartStopExtProgram/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Test_StartStopExtProgram/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Test_StartStopExtProgram/Properties/Settings.Designer.cs b/Test_StartStopExtProgram/Properties/Settings.Designer.cs new file mode 100644 index 0000000..0b35572 --- /dev/null +++ b/Test_StartStopExtProgram/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Test_StartStopExtProgram.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Test_StartStopExtProgram/Properties/Settings.settings b/Test_StartStopExtProgram/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Test_StartStopExtProgram/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Test_StartStopExtProgram/Test_StartStopExtProgram.csproj b/Test_StartStopExtProgram/Test_StartStopExtProgram.csproj new file mode 100644 index 0000000..ba5292c --- /dev/null +++ b/Test_StartStopExtProgram/Test_StartStopExtProgram.csproj @@ -0,0 +1,92 @@ + + + + + Debug + AnyCPU + {A8D979D5-120D-4649-9E74-FA646A3E57D2} + WinExe + Test_StartStopExtProgram + Test_StartStopExtProgram + v4.6.1 + 512 + true + false + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + Form1.cs + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {d9fa7eae-2785-4856-bd44-1320c7e3bd39} + StartStopExtProgram + + + + \ No newline at end of file