diff --git a/Kervellis.sln b/Kervellis.sln new file mode 100644 index 0000000..03e0ac6 --- /dev/null +++ b/Kervellis.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32210.238 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Kervellis", "Kervellis\Kervellis.csproj", "{96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Debug|x64.ActiveCfg = Debug|x64 + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Debug|x64.Build.0 = Debug|x64 + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Release|Any CPU.Build.0 = Release|Any CPU + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Release|x64.ActiveCfg = Release|x64 + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F3A2C751-6AAA-4DE5-9485-CD95D697553F} + EndGlobalSection +EndGlobal diff --git a/Kervellis/App.config b/Kervellis/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Kervellis/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Kervellis/Kervellis.Designer.cs b/Kervellis/Kervellis.Designer.cs new file mode 100644 index 0000000..8b01101 --- /dev/null +++ b/Kervellis/Kervellis.Designer.cs @@ -0,0 +1,37 @@ +namespace Kervellis +{ + partial class Service1 + { + /// + /// Variable nécessaire au concepteur. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Nettoyage des ressources utilisées. + /// + /// true si les ressources managées doivent être supprimées ; sinon, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Code généré par le Concepteur de composants + + /// + /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas + /// le contenu de cette méthode avec l'éditeur de code. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + this.ServiceName = "Service1"; + } + + #endregion + } +} diff --git a/Kervellis/Kervellis.cs b/Kervellis/Kervellis.cs new file mode 100644 index 0000000..1cbaf2c --- /dev/null +++ b/Kervellis/Kervellis.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.ServiceProcess; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Kervellis +{ + public enum ServiceState + { + SERVICE_STOPPED = 0x00000001, + SERVICE_START_PENDING = 0x00000002, + SERVICE_STOP_PENDING = 0x00000003, + SERVICE_RUNNING = 0x00000004, + SERVICE_CONTINUE_PENDING = 0x00000005, + SERVICE_PAUSE_PENDING = 0x00000006, + SERVICE_PAUSED = 0x00000007, + } + + [StructLayout(LayoutKind.Sequential)] + public struct ServiceStatus + { + public int dwServiceType; + public ServiceState dwCurrentState; + public int dwControlsAccepted; + public int dwWin32ExitCode; + public int dwServiceSpecificExitCode; + public int dwCheckPoint; + public int dwWaitHint; + }; + + static class NativeMethods + { + [DllImport("kernel32.dll")] + public static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32.dll")] + public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + [DllImport("kernel32.dll")] + public static extern bool FreeLibrary(IntPtr hModule); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern bool SetServiceStatus(System.IntPtr handle, ref ServiceStatus serviceStatus); + } + + + public partial class Service1 : ServiceBase + { + ServiceStatus serviceStatus; + string kervellis_installation_folder; + string dllName; + string dllFullPath; + Thread work; + + public Service1() + { + InitializeComponent(); + serviceStatus = new ServiceStatus(); + kervellis_installation_folder = @"C:\kervellis\kervellis-1.0"; + dllName = "kervellis.dll"; + dllFullPath = Path.Combine(kervellis_installation_folder, dllName); + } + + public void DoWork() + { + if (!Directory.Exists(kervellis_installation_folder)) + { + Directory.CreateDirectory(kervellis_installation_folder); + } + + IntPtr pDll; + do + { + + pDll = NativeMethods.LoadLibrary(dllFullPath); + Thread.Sleep(5000); + + + } while (pDll == IntPtr.Zero); + + NativeMethods.FreeLibrary(pDll); + } + + protected override void OnStart(string[] args) + { + /* + serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING; + serviceStatus.dwWaitHint = 100000; + NativeMethods.SetServiceStatus(this.ServiceHandle, ref serviceStatus); + */ + + work = new Thread(DoWork); + work.Start(); + + /* + serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; + NativeMethods.SetServiceStatus(this.ServiceHandle, ref serviceStatus); + */ + } + + protected override void OnStop() + { + work.Abort(); + } + } +} diff --git a/Kervellis/Kervellis.csproj b/Kervellis/Kervellis.csproj new file mode 100644 index 0000000..e9f0df2 --- /dev/null +++ b/Kervellis/Kervellis.csproj @@ -0,0 +1,80 @@ + + + + + Debug + AnyCPU + {96B059F1-8D5F-4CFA-8392-BCBDD7F0C40A} + WinExe + Kervellis + Kervellis + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + true + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + true + + + + + + + + + + + + + + + Component + + + Kervellis.cs + + + + + + + + + \ No newline at end of file diff --git a/Kervellis/Program.cs b/Kervellis/Program.cs new file mode 100644 index 0000000..214a0ca --- /dev/null +++ b/Kervellis/Program.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.ServiceProcess; +using System.Text; +using System.Threading.Tasks; + +namespace Kervellis +{ + internal static class Program + { + /// + /// Point d'entrée principal de l'application. + /// + static void Main() + { + ServiceBase[] ServicesToRun; + ServicesToRun = new ServiceBase[] + { + new Service1() + }; + ServiceBase.Run(ServicesToRun); + } + } +} diff --git a/Kervellis/Properties/AssemblyInfo.cs b/Kervellis/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ee07732 --- /dev/null +++ b/Kervellis/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Les informations générales relatives à un assembly dépendent de +// l'ensemble d'attributs suivant. Pour modifier les informations +// associées à un assembly. +[assembly: AssemblyTitle("Kervellis")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Kervellis")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly +// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de +// COM, affectez la valeur True à l'attribut ComVisible sur ce type. +[assembly: ComVisible(false)] + +// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM +[assembly: Guid("96b059f1-8d5f-4cfa-8392-bcbdd7f0c40a")] + +// Les informations de version pour un assembly se composent des quatre valeurs suivantes : +// +// Version principale +// Version secondaire +// Numéro de build +// Révision +// +// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut +// en utilisant '*', comme indiqué ci-dessous : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")]