Example #1
0
        //...

        static void startService()
        {
            Guid webCleintTrigger = new Guid(0xb52c6d34, 0x59c9, 0x4dfc, 0x80, 0xcb, 0x3b, 0x65, 0x2, 0xf5, 0xd5, 0xcc);

            long handle = 0;
            uint output = EventRegister(ref webCleintTrigger, IntPtr.Zero, IntPtr.Zero, ref handle);

            //This is what is returned:
            //output = 0 <- Good
            //handle = 65537  <- Good handle?

            bool success = false;

            if (output == 0)
            {
                //Create event descriptor
                EVENT_DESCRIPTOR desc = new EVENT_DESCRIPTOR();

                //Write the event
                unsafe
                {
                    uint writeOutput = EventWrite(handle, ref desc, 0, null);
                    success = writeOutput == 0;

                    EventUnregister(handle);
                }
            }
        }
Example #2
0
        //...
        static void startService()
        {
            Guid webCleintTrigger = new Guid(0xb52c6d34, 0x59c9, 0x4dfc, 0x80, 0xcb, 0x3b, 0x65, 0x2, 0xf5, 0xd5, 0xcc);

            long handle = 0;
            uint output = EventRegister(ref webCleintTrigger, IntPtr.Zero, IntPtr.Zero, ref handle);

            //This is what is returned:
            //output = 0 <- Good
            //handle = 65537  <- Good handle?

            bool success = false;

            if (output == 0)
            {
                //Create event descriptor
                EVENT_DESCRIPTOR desc = new EVENT_DESCRIPTOR();

                //Write the event
                unsafe
                {
                    uint writeOutput = EventWrite(handle, ref desc, 0, null);
                    success = writeOutput == 0;

                    EventUnregister(handle);
                }

            }
        }
Example #3
0
        public static void start_service(string trigger)
        {
            Guid webCleintTrigger = new Guid(0x22B6D684, 0xFA63, 0x4578, 0x87, 0xC9, 0xEF, 0xFC, 0xBE, 0x66, 0x43, 0xC7);

            if (trigger.ToLower().Equals("true"))
            {
                Console.WriteLine("Attempting to start WebClient via ServiceTrigger");
            }
            else
            {
                Console.WriteLine("Attempting to start {0} via ServiceTrigger", trigger);
                webCleintTrigger = new Guid(trigger);
            }

            long handle  = 0;
            uint output  = EventRegister(ref webCleintTrigger, IntPtr.Zero, IntPtr.Zero, ref handle);
            bool success = false;

            if (output == 0)
            {
                //Create event descriptor
                EVENT_DESCRIPTOR desc = new EVENT_DESCRIPTOR();

                //Write the event
                uint writeOutput = EventWrite(handle, ref desc, 0, IntPtr.Zero);
                success = writeOutput == 0;
                EventUnregister(handle);
                Console.WriteLine("Service should be started, verify with \"sc.exe query servicename\"");
            }
        }
Example #4
0
        public void EventTest()
        {
            var activId = Guid.Empty;

            Assert.That(EventActivityIdControl(EVENT_ACTIVITY_CTRL.EVENT_ACTIVITY_CTRL_CREATE_ID, ref activId), ResultIs.Successful);

            var provGuid = Guid.NewGuid();

            Assert.That(EventRegister(provGuid, Callback, IntPtr.Zero, out var hReg), ResultIs.Successful);
            Assert.That(hReg.IsInvalid, Is.False);

            using (hReg)
            {
                var desc = new EVENT_DESCRIPTOR(0, 0, 0, 0, 0, 0, ulong.MaxValue);
                Assert.That(EventEnabled(hReg, desc), Is.False);

                Assert.That(EventProviderEnabled(hReg, 0, ulong.MaxValue), Is.False);

                using (var mem = SafeHGlobalHandle.CreateFromStructure((byte)1))
                    Assert.That(EventSetInformation(hReg, EVENT_INFO_CLASS.EventProviderUseDescriptorType, mem, 1U), ResultIs.FailureCode(Win32Error.ERROR_NOT_SUPPORTED));

                Assert.That(EventWrite(hReg, desc, 0, null), ResultIs.FailureCode(Win32Error.ERROR_INVALID_PARAMETER));
                Assert.That(EventWriteEx(hReg, desc, 0, 0, IntPtr.Zero, IntPtr.Zero, 0, null), ResultIs.FailureCode(Win32Error.ERROR_INVALID_PARAMETER));
                Assert.That(EventWriteString(hReg, 0, ulong.MaxValue, "Dummy"), ResultIs.FailureCode(Win32Error.ERROR_INVALID_HANDLE));
                Assert.That(EventWriteTransfer(hReg, desc, IntPtr.Zero, IntPtr.Zero, 0, null), ResultIs.FailureCode(Win32Error.ERROR_INVALID_PARAMETER));
            }

            void Callback(in Guid SourceId, bool IsEnabled, byte Level, ulong MatchAnyKeyword, ulong MatchAllKeyword, IntPtr FilterData, IntPtr CallbackContext)
            {
            }
        }
        public static bool Start(string serviceGuid)
        {
            long handle      = 0;
            bool success     = false;
            Guid triggerGuid = new Guid(serviceGuid);

            if (Advapi32.EventRegister(ref triggerGuid, IntPtr.Zero, IntPtr.Zero, ref handle) == 0)
            {
                EVENT_DESCRIPTOR desc = new EVENT_DESCRIPTOR();
                success = Advapi32.EventWrite(handle, ref desc, 0, IntPtr.Zero) == 0;
                Advapi32.EventUnregister(handle);
                return(success);
            }
            return(success);
        }
Example #6
0
 public static unsafe extern uint EventWrite(long RegHandle, ref EVENT_DESCRIPTOR EventDescriptor, uint UserDataCount, EventData* UserData);
Example #7
0
 public static extern unsafe uint EventWrite(long RegHandle, ref EVENT_DESCRIPTOR EventDescriptor, uint UserDataCount, EventData *UserData);