<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Decrypt my World : NT Services</title><link>http://blogs.msdn.com/alejacma/archive/tags/NT+Services/default.aspx</link><description>Tags: NT Services</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to debug Windows services with Windbg</title><link>http://blogs.msdn.com/alejacma/archive/2008/08/19/how-to-debug-windows-services-through-terminal-services-on-windows-2000.aspx</link><pubDate>Tue, 19 Aug 2008 09:46:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8878097</guid><dc:creator>alejacma</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/8878097.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=8878097</wfw:commentRss><description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;If you want to know how to &lt;STRONG&gt;debug a Windows&amp;nbsp;service&lt;/STRONG&gt;, the following article will be of great assistance: &lt;A class="" href="http://support.microsoft.com/kb/824344/en-us" mce_href="http://support.microsoft.com/kb/824344/en-us"&gt;How to debug Windows services&lt;/A&gt;. I suggest you read this article before you continue reading this post. Also, you should have &lt;A class="" href="http://www.microsoft.com/whdc/devtools/debugging/installx86.Mspx" mce_href="http://www.microsoft.com/whdc/devtools/debugging/installx86.Mspx"&gt;Debugging Tools for Windows&lt;/A&gt; installed in your machine; the tools I'll mention (windbg.exe, cdb.exe, gflags.exe &amp;amp; remote.exe) are part of them.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically, we can &lt;STRONG&gt;attach a debugger to a service&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;a) Just &lt;STRONG&gt;when process starts&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1) Go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control registry key and add or modify &lt;STRONG&gt;ServicesPipeTimeout&lt;/STRONG&gt; REG_DWORD value to i.e. 3600000 (1h in milliseconds). Restart machine to apply changes. Default is 30 seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2) Use &lt;STRONG&gt;Gflags&lt;/STRONG&gt; to associate a debugger to the service. The debugger will attach to the service when starting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2.1) If &lt;STRONG&gt;service interacts with desktop&lt;/STRONG&gt;, we can&amp;nbsp;associate &lt;STRONG&gt;'&lt;EM&gt;windgb&lt;/EM&gt;'&lt;/STRONG&gt; to the service directly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2.2) If &lt;STRONG&gt;service won't interact with desktop&lt;/STRONG&gt;, we can associate &lt;STRONG&gt;'&lt;EM&gt;cdb -server tcp:port=9999&lt;/EM&gt;'&lt;/STRONG&gt; to the service instead. Cdb.exe is the command line version of Windbg. It will attach to the service and expose itself as a server. Then we can launch and connect a windbg instance to that cdb with &lt;STRONG&gt;'&lt;EM&gt;windbg.exe -remote tcp:Port=9999,Server=machinename&lt;/EM&gt;'&lt;/STRONG&gt; and control it remotely. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Note: I use cdb to attach to the service because windbg may fail to start if service won't interact with desktop. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; 3) Don't&amp;nbsp;forget to &lt;STRONG&gt;undo&lt;/STRONG&gt; registry and gflags &lt;STRONG&gt;changes&lt;/STRONG&gt; once you are done debugging.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;b) &lt;STRONG&gt;At any time&lt;/STRONG&gt;. Just find out the service's process ID (PID) or name and attach a debugger to it with i.e. &lt;STRONG&gt;'&lt;EM&gt;windbg -p PID&lt;/EM&gt;'&lt;/STRONG&gt; or&lt;STRONG&gt; '&lt;/STRONG&gt;&lt;STRONG&gt;&lt;EM&gt;windbg -pn servicename.exe&lt;/EM&gt;'&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Here you may have an issue on &lt;STRONG&gt;Windows 2000&lt;/STRONG&gt;, for instance. We can only do live debugging on Windows 2000 if we are in the same &lt;STRONG&gt;Window Station&lt;/STRONG&gt; as the process we are debugging. When we connect through &lt;STRONG&gt;Terminal Services&lt;/STRONG&gt;, we are in a different Window Station than the &lt;STRONG&gt;services&lt;/STRONG&gt;, so &lt;STRONG&gt;we can’t attach to their processes&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;On Windows Server 2003, for instance, we can cross the barrier between WinStations. More info on WinStations here: &lt;A class="" href="http://support.microsoft.com/kb/171890/en-us" mce_href="http://support.microsoft.com/kb/171890/en-us"&gt;INFO: Services, Desktops, and Window Stations&lt;/A&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;So in order to &lt;STRONG&gt;debug services with Windbg on Windows 2000&lt;/STRONG&gt; we can do the following:&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; 1) Use &lt;STRONG&gt;AT command&lt;/STRONG&gt; to launch &lt;STRONG&gt;remote.exe&lt;/STRONG&gt; and expose a &lt;STRONG&gt;cmd.exe&lt;/STRONG&gt; as a &lt;STRONG&gt;server&lt;/STRONG&gt; with &lt;STRONG&gt;'&lt;EM&gt;at 14:48 remote /S cmd "any string"&lt;/EM&gt;'&lt;/STRONG&gt;. AT command launches a process under the System acccount at a given time. Remote.exe is a very cool tool which exposes any command line tool as a server. Cmd.exe won't be visible and it will be running under System account in the same WinStation as the services. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; Note: We may also use Task Scheduler or any other app which allows us to launch processes under the &lt;STRONG&gt;System account&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; 2) Use &lt;STRONG&gt;remote.exe&lt;/STRONG&gt; to launch another &lt;STRONG&gt;cmd.exe&lt;/STRONG&gt; as a &lt;STRONG&gt;client&lt;/STRONG&gt; of server cmd instance with &lt;STRONG&gt;'remote &lt;EM&gt;/C machinename "any string"&lt;/EM&gt;'&lt;/STRONG&gt;. Now we can control the invisible cmd.exe which is running under System account.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; 3) Thanks to client cmd we can tell server cmd to launch &lt;STRONG&gt;cdb.exe&lt;/STRONG&gt; and &lt;STRONG&gt;attach&lt;/STRONG&gt; to the service with i.e. &lt;STRONG&gt;'&lt;EM&gt;cdb -p PID&lt;/EM&gt;'&lt;/STRONG&gt;. We can now&amp;nbsp;use cdb to debug the service directly, as cdb is running as System in &lt;STRONG&gt;same WinStation&lt;/STRONG&gt; as services.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp; 4) If we prefer to debug with &lt;STRONG&gt;Windbg.exe&lt;/STRONG&gt; instead of&amp;nbsp;cdb (so we can do live debugging with source code, for instance) we can expose cdb as a server with its&amp;nbsp;&lt;STRONG&gt;'&lt;EM&gt;.server tcp:port=9999&lt;/EM&gt;'&lt;/STRONG&gt; command and connect to it with '&lt;STRONG&gt;&lt;EM&gt;windbg.exe -remote tcp:Port=9999,Server=machinename&lt;/EM&gt;'&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;I hope this helps.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Regards,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8878097" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/WinDbg/default.aspx">WinDbg</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Cdb/default.aspx">Cdb</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.msdn.com/alejacma/archive/tags/NT+Services/default.aspx">NT Services</category></item><item><title>How To Host an NT Service on svchost.exe</title><link>http://blogs.msdn.com/alejacma/archive/2008/01/08/how-to-host-an-nt-service-on-svchost-exe.aspx</link><pubDate>Tue, 08 Jan 2008 18:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7029201</guid><dc:creator>alejacma</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/alejacma/comments/7029201.aspx</comments><wfw:commentRss>http://blogs.msdn.com/alejacma/commentrss.aspx?PostID=7029201</wfw:commentRss><description>&lt;P&gt;Hi all, welcome back,&lt;/P&gt;
&lt;P&gt;This How To will be very short, because the answer is plain and simple: it's &lt;STRONG&gt;not supported&lt;/STRONG&gt; to host non-windows services in &lt;STRONG&gt;svchost.exe&lt;/STRONG&gt;, it's for MS Windows Services only.&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P mce_keep="true"&gt;Cheers,&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alex (Alejandro Campos Magencio)&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS: Happy New Year to you all! I've chosen a short post for this week because I just came back from vacation and I'm still trying to catch up...&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7029201" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/alejacma/archive/tags/NT+Services/default.aspx">NT Services</category></item></channel></rss>