{"id":1068,"date":"2016-10-20T12:36:45","date_gmt":"2016-10-20T11:36:45","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=1068"},"modified":"2016-10-20T12:36:45","modified_gmt":"2016-10-20T11:36:45","slug":"how-to-start-a-trigger-start-windows-service-with-powershell-without-elevation-admin-rights","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2016\/10\/how-to-start-a-trigger-start-windows-service-with-powershell-without-elevation-admin-rights\/","title":{"rendered":"How to start a &#8220;Trigger Start&#8221; windows service with Powershell without elevation \/ admin rights"},"content":{"rendered":"<p>Some Windows services can be triggered to start at certain events. These services have &#8216;Tigger Start&#8217; in their startup name behind whatever you configured (like Manual).<\/p>\n<p>Powershell does not have a native method to register the type of event that triggers such a service, C++ and C# do&#8230;..and Powershell can natively run C#.<\/p>\n<p>To trigger a service, you&#8217;ll need its guid first:<\/p>\n<p>run sc triggerinfo &lt;SERVICENAME&gt;<\/p>\n<p>This will give you a GUID, for example for the WebClient service:<\/p>\n<pre>22b6d684-fa63-4578-87c9-effcbe6643c7<\/pre>\n<p>You can then use this GUID in the following script to trigger your service from Powershell \ud83d\ude42<!--more--><\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n\n$Source = @&quot;\nusing System;\nusing System.Text;\nusing System.Security;\nusing System.Collections.Generic;\nusing System.Runtime.Versioning;\nusing Microsoft.Win32.SafeHandles;\nusing System.Runtime.InteropServices;\nusing System.Diagnostics.CodeAnalysis;\nnamespace JosL.WebClient{\npublic static class Starter{\n&#x5B;StructLayout(LayoutKind.Explicit, Size=16)]\npublic class EVENT_DESCRIPTOR{\n&#x5B;FieldOffset(0)]ushort Id = 1;\n&#x5B;FieldOffset(2)]byte Version = 0;\n&#x5B;FieldOffset(3)]byte Channel = 0;\n&#x5B;FieldOffset(4)]byte Level = 4;\n&#x5B;FieldOffset(5)]byte Opcode = 0;\n&#x5B;FieldOffset(6)]ushort Task = 0;\n&#x5B;FieldOffset(8)]long Keyword = 0;\n}\n\n&#x5B;StructLayout(LayoutKind.Explicit, Size = 16)]\npublic struct EventData{\n&#x5B;FieldOffset(0)]\ninternal UInt64 DataPointer;\n&#x5B;FieldOffset(8)]\ninternal uint Size;\n&#x5B;FieldOffset(12)]\ninternal int Reserved;\n}\n\npublic static void startService(){\nGuid webClientTrigger = new Guid(0x22B6D684, 0xFA63, 0x4578, 0x87, 0xC9, 0xEF, 0xFC, 0xBE, 0x66, 0x43, 0xC7);\n\nlong handle = 0;\nuint output = EventRegister(ref webClientTrigger, IntPtr.Zero, IntPtr.Zero, ref handle);\n\nbool success = false;\n\nif (output == 0){\nEVENT_DESCRIPTOR desc = new EVENT_DESCRIPTOR();\nunsafe\n{\nuint writeOutput = EventWrite(handle, ref desc, 0, null);\nsuccess = writeOutput == 0;\nEventUnregister(handle);\n}\n}\n}\n\n&#x5B;DllImport(&quot;Advapi32.dll&quot;, SetLastError = true)]\npublic static extern uint EventRegister(ref Guid guid, &#x5B;Optional] IntPtr EnableCallback, &#x5B;Optional] IntPtr CallbackContext, &#x5B;In]&#x5B;Out] ref long RegHandle);\n\n&#x5B;DllImport(&quot;Advapi32.dll&quot;, SetLastError = true)]\npublic static extern unsafe uint EventWrite(long RegHandle, ref EVENT_DESCRIPTOR EventDescriptor, uint UserDataCount, EventData* UserData);\n\n&#x5B;DllImport(&quot;Advapi32.dll&quot;, SetLastError = true)]\npublic static extern uint EventUnregister(long RegHandle);\n}\n}\n&quot;@\n$compilerParameters = New-Object System.CodeDom.Compiler.CompilerParameters\n$compilerParameters.CompilerOptions=&quot;\/unsafe&quot;\nAdd-Type -TypeDefinition $Source -Language CSharp -CompilerParameters $compilerParameters\n&#x5B;JosL.WebClient.Starter]::startService()\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Some Windows services can be triggered to start at certain events. These services have &#8216;Tigger Start&#8217; in their startup name behind whatever you configured (like Manual). Powershell does not have a native method to register the type of event that triggers such a service, C++ and C# do&#8230;..and Powershell can natively run C#. To trigger &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2016\/10\/how-to-start-a-trigger-start-windows-service-with-powershell-without-elevation-admin-rights\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to start a &#8220;Trigger Start&#8221; windows service with Powershell without elevation \/ admin rights<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[4,39],"tags":[],"class_list":["post-1068","post","type-post","status-publish","format-standard","hentry","category-automation","category-powershell"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/1068","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=1068"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/1068\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=1068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=1068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=1068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}