Exemplo n.º 1
0
 private System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY GetEntry()
 {
     System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY service_table_entry = new System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY();
     this.nameFrozen = true;
     service_table_entry.callback = this.mainCallback;
     service_table_entry.name     = this.handleName;
     return(service_table_entry);
 }
Exemplo n.º 2
0
 public static void Run(ServiceBase[] services)
 {
     if ((services == null) || (services.Length == 0))
     {
         throw new ArgumentException(Res.GetString("NoServices"));
     }
     if (Environment.OSVersion.Platform != PlatformID.Win32NT)
     {
         string message = Res.GetString("CantRunOnWin9x");
         string title   = Res.GetString("CantRunOnWin9xTitle");
         LateBoundMessageBoxShow(message, title);
     }
     else
     {
         IntPtr entry = Marshal.AllocHGlobal((IntPtr)((services.Length + 1) * Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY))));
         System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY[] service_table_entryArray = new System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY[services.Length];
         bool   multipleServices = services.Length > 1;
         IntPtr zero             = IntPtr.Zero;
         for (int i = 0; i < services.Length; i++)
         {
             services[i].Initialize(multipleServices);
             service_table_entryArray[i] = services[i].GetEntry();
             zero = (IntPtr)(((long)entry) + (Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY)) * i));
             Marshal.StructureToPtr(service_table_entryArray[i], zero, true);
         }
         System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY structure = new System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY {
             callback = null,
             name     = IntPtr.Zero
         };
         zero = (IntPtr)(((long)entry) + (Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY)) * services.Length));
         Marshal.StructureToPtr(structure, zero, true);
         bool   flag2 = System.ServiceProcess.NativeMethods.StartServiceCtrlDispatcher(entry);
         string str3  = "";
         if (!flag2)
         {
             str3 = new Win32Exception().Message;
             string str4 = Res.GetString("CantStartFromCommandLine");
             if (Environment.UserInteractive)
             {
                 string str5 = Res.GetString("CantStartFromCommandLineTitle");
                 LateBoundMessageBoxShow(str4, str5);
             }
             else
             {
                 Console.WriteLine(str4);
             }
         }
         foreach (ServiceBase base2 in services)
         {
             base2.Dispose();
             if (!flag2 && (base2.EventLog.Source.Length != 0))
             {
                 base2.WriteEventLogEntry(Res.GetString("StartFailed", new object[] { str3 }), EventLogEntryType.Error);
             }
         }
     }
 }
 public static void Run(ServiceBase[] services)
 {
     if ((services == null) || (services.Length == 0))
     {
         throw new ArgumentException(Res.GetString("NoServices"));
     }
     if (Environment.OSVersion.Platform != PlatformID.Win32NT)
     {
         string message = Res.GetString("CantRunOnWin9x");
         string title = Res.GetString("CantRunOnWin9xTitle");
         LateBoundMessageBoxShow(message, title);
     }
     else
     {
         IntPtr entry = Marshal.AllocHGlobal((IntPtr) ((services.Length + 1) * Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY))));
         System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY[] service_table_entryArray = new System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY[services.Length];
         bool multipleServices = services.Length > 1;
         IntPtr zero = IntPtr.Zero;
         for (int i = 0; i < services.Length; i++)
         {
             services[i].Initialize(multipleServices);
             service_table_entryArray[i] = services[i].GetEntry();
             zero = (IntPtr) (((long) entry) + (Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY)) * i));
             Marshal.StructureToPtr(service_table_entryArray[i], zero, true);
         }
         System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY structure = new System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY {
             callback = null,
             name = IntPtr.Zero
         };
         zero = (IntPtr) (((long) entry) + (Marshal.SizeOf(typeof(System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY)) * services.Length));
         Marshal.StructureToPtr(structure, zero, true);
         bool flag2 = System.ServiceProcess.NativeMethods.StartServiceCtrlDispatcher(entry);
         string str3 = "";
         if (!flag2)
         {
             str3 = new Win32Exception().Message;
             string str4 = Res.GetString("CantStartFromCommandLine");
             if (Environment.UserInteractive)
             {
                 string str5 = Res.GetString("CantStartFromCommandLineTitle");
                 LateBoundMessageBoxShow(str4, str5);
             }
             else
             {
                 Console.WriteLine(str4);
             }
         }
         foreach (ServiceBase base2 in services)
         {
             base2.Dispose();
             if (!flag2 && (base2.EventLog.Source.Length != 0))
             {
                 base2.WriteEventLogEntry(Res.GetString("StartFailed", new object[] { str3 }), EventLogEntryType.Error);
             }
         }
     }
 }
 private System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY GetEntry()
 {
     System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY service_table_entry = new System.ServiceProcess.NativeMethods.SERVICE_TABLE_ENTRY();
     this.nameFrozen = true;
     service_table_entry.callback = this.mainCallback;
     service_table_entry.name = this.handleName;
     return service_table_entry;
 }