Example #1
0
        public int                             ServiceRun()
        {
            if (_console)
            {
                _writeConsole(AppDomain.CurrentDomain.FriendlyName + ": Cannot run service in console.");
                return(-1);
            }

            _stopping    = false;
            _shutingdown = false;
            _eventLog    = new EventLog("Application")
            {
                Source = _serviceName
            };

            if (Environment.OSVersion.Platform != PlatformID.Win32NT ||
                Environment.OSVersion.Version.Major < 5)
            {
                throw new Exception("Can only run on W2K or higher.");
            }

            unsafe
            {
                NativeMethods.SERVICE_TABLE_ENTRY[] entryTable = new NativeMethods.SERVICE_TABLE_ENTRY[2];
                entryTable[0].name     = _serviceName;
                entryTable[0].callback = new NativeMethods.ServiceMainCallback(this._serviceMainCallback);

                if (!NativeMethods.StartServiceCtrlDispatcher(entryTable))
                {
                    throw NativeMethods.NewSystemError("StartServiceCtrlDispatcher failed");
                }
            }

            return(0);
        }
Example #2
0
 // Token: 0x06001EC5 RID: 7877 RVA: 0x0008BA64 File Offset: 0x00089C64
 private NativeMethods.SERVICE_TABLE_ENTRY GetEntry()
 {
     NativeMethods.SERVICE_TABLE_ENTRY service_TABLE_ENTRY = new NativeMethods.SERVICE_TABLE_ENTRY();
     this.nameFrozen = true;
     service_TABLE_ENTRY.callback = this.mainCallback;
     service_TABLE_ENTRY.name     = this.handleName;
     return(service_TABLE_ENTRY);
 }
Example #3
0
        // Token: 0x06001EA4 RID: 7844 RVA: 0x0008AD14 File Offset: 0x00088F14
        public static void Run(ReplayServiceBase[] services)
        {
            if (services == null || services.Length == 0)
            {
                throw new ArgumentException(ReplayStrings.NoServices);
            }
            IntPtr intPtr = Marshal.AllocHGlobal((IntPtr)((services.Length + 1) * Marshal.SizeOf(typeof(NativeMethods.SERVICE_TABLE_ENTRY))));

            NativeMethods.SERVICE_TABLE_ENTRY[] array = new NativeMethods.SERVICE_TABLE_ENTRY[services.Length];
            bool   multipleServices = services.Length > 1;
            IntPtr ptr = (IntPtr)0;

            for (int i = 0; i < services.Length; i++)
            {
                services[i].Initialize(multipleServices);
                array[i] = services[i].GetEntry();
                ptr      = (IntPtr)((long)intPtr + (long)(Marshal.SizeOf(typeof(NativeMethods.SERVICE_TABLE_ENTRY)) * i));
                Marshal.StructureToPtr(array[i], ptr, true);
            }
            NativeMethods.SERVICE_TABLE_ENTRY service_TABLE_ENTRY = new NativeMethods.SERVICE_TABLE_ENTRY();
            service_TABLE_ENTRY.callback = null;
            service_TABLE_ENTRY.name     = (IntPtr)0;
            ptr = (IntPtr)((long)intPtr + (long)(Marshal.SizeOf(typeof(NativeMethods.SERVICE_TABLE_ENTRY)) * services.Length));
            Marshal.StructureToPtr(service_TABLE_ENTRY, ptr, true);
            bool   flag = NativeMethods.StartServiceCtrlDispatcher(intPtr);
            string text = "";

            if (!flag)
            {
                text = new Win32Exception().Message;
                string text2 = ReplayStrings.CantStartFromCommandLine;
                if (Environment.UserInteractive)
                {
                    string title = ReplayStrings.CantStartFromCommandLineTitle;
                    ReplayServiceBase.LateBoundMessageBoxShow(text2, title);
                }
                else
                {
                    Console.WriteLine(text2);
                }
            }
            foreach (ReplayServiceBase replayServiceBase in services)
            {
                replayServiceBase.Dispose();
                if (!flag)
                {
                    ReplayEventLogConstants.Tuple_StartFailed.LogEvent(null, new object[]
                    {
                        text
                    });
                }
            }
        }
Example #4
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;
 }
Example #5
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);
         }
     }
 }