Exemple #1
0
 private NativeMethods.SERVICE_TABLE_ENTRY GetEntry()
 {
     NativeMethods.SERVICE_TABLE_ENTRY serviceTableEntry = new NativeMethods.SERVICE_TABLE_ENTRY();
     this.nameFrozen            = true;
     serviceTableEntry.callback = (Delegate)this.mainCallback;
     serviceTableEntry.name     = this.handleName;
     return(serviceTableEntry);
 }
Exemple #2
0
 public static void Run(MyServiceBase[] services)
 {
     if (services == null || services.Length == 0)
     {
         throw new ArgumentException(GetString("NoServices"));
     }
     if (Environment.OSVersion.Platform != PlatformID.Win32NT)
     {
         MyServiceBase.LateBoundMessageBoxShow(GetString("CantRunOnWin9x"), GetString("CantRunOnWin9xTitle"));
     }
     else
     {
         IntPtr entry = Marshal.AllocHGlobal((IntPtr)((services.Length + 1) * Marshal.SizeOf(typeof(NativeMethods.SERVICE_TABLE_ENTRY))));
         NativeMethods.SERVICE_TABLE_ENTRY[] serviceTableEntryArray = new NativeMethods.SERVICE_TABLE_ENTRY[services.Length];
         bool   multipleServices = services.Length > 1;
         IntPtr num = (IntPtr)0;
         for (int index = 0; index < services.Length; ++index)
         {
             services[index].Initialize(multipleServices);
             serviceTableEntryArray[index] = services[index].GetEntry();
             IntPtr ptr = (IntPtr)((long)entry + (long)(Marshal.SizeOf(typeof(NativeMethods.SERVICE_TABLE_ENTRY)) * index));
             Marshal.StructureToPtr((object)serviceTableEntryArray[index], ptr, true);
         }
         NativeMethods.SERVICE_TABLE_ENTRY serviceTableEntry = new NativeMethods.SERVICE_TABLE_ENTRY();
         serviceTableEntry.callback = (Delegate)null;
         serviceTableEntry.name     = (IntPtr)0;
         IntPtr ptr1 = (IntPtr)((long)entry + (long)(Marshal.SizeOf(typeof(NativeMethods.SERVICE_TABLE_ENTRY)) * services.Length));
         Marshal.StructureToPtr((object)serviceTableEntry, ptr1, true);
         bool   flag = NativeMethods.StartServiceCtrlDispatcher(entry);
         string str  = "";
         if (!flag)
         {
             str = new Win32Exception().Message;
             string string1 = GetString("CantStartFromCommandLine");
             if (Environment.UserInteractive)
             {
                 string string2 = GetString("CantStartFromCommandLineTitle");
                 MyServiceBase.LateBoundMessageBoxShow(string1, string2);
             }
             else
             {
                 Console.WriteLine(string1);
             }
         }
         foreach (MyServiceBase serviceBase in services)
         {
             serviceBase.Dispose();
             if (!flag && serviceBase.EventLog.Source.Length != 0)
             {
                 serviceBase.WriteEventLogEntry(GetString("StartFailed", new object[1]
                 {
                     (object)str
                 }), EventLogEntryType.Error);
             }
         }
     }
 }