{"id":230,"date":"2016-02-29T17:04:23","date_gmt":"2016-02-29T16:04:23","guid":{"rendered":"http:\/\/www.riedmann.it\/blog\/?p=230"},"modified":"2016-02-29T17:05:50","modified_gmt":"2016-02-29T16:05:50","slug":"windows-service-caveats-with-process-start","status":"publish","type":"post","link":"https:\/\/blog.riedmann.it\/?p=230","title":{"rendered":"Windows service caveats with Process.Start"},"content":{"rendered":"<p>These days, I was working on a webservice that worked directly with http.sys.<br \/>\nThis service was planned to wait for requests, and launch programs depending on the request.<br \/>\nFirstly, I planned to use the local system account, and launch the external programs as specific user. This program should be started from a network share, using UNC paths.<br \/>\nUnfortunately, that does not work, Process.Start cannot do that:<br \/>\n<a href=\"http:\/\/blogs.msdn.com\/b\/winsdk\/archive\/2013\/11\/12\/runas-verb-process-start-doesn-t-work-from-a-localsystem-net-service.aspx\" target=\"_blank\">http:\/\/blogs.msdn.com\/b\/winsdk\/archive\/2013\/11\/12\/runas-verb-process-start-doesn-t-work-from-a-localsystem-net-service.aspx<\/a><\/p>\n<p>My next decision was to add a user for this purpose (to run the Windows service). Unfortunately, Process.Start ignores the essential settings for a Windows service<\/p>\n<blockquote><p><code>oInfo:UseShellExecute := false<br \/>\n\t\toInfo:CreateNoWindow := true<br \/>\n\t\toInfo:ErrorDialog := false<br \/>\n\t\toInfo:WindowStyle := ProcessWindowStyle.Hidden<\/code><\/p><\/blockquote>\n<p>The page from MSDN (<a href=\"https:\/\/msdn.microsoft.com\/library\/0w4h05yb%28v=vs.100%29.aspx\" target=\"_blank\">https:\/\/msdn.microsoft.com\/library\/0w4h05yb%28v=vs.100%29.aspx<\/a>) states:<br \/>\n&#8220;If the UserName and Password properties of the StartInfo instance are set, the unmanaged CreateProcessWithLogonW function is called, which starts the process in a new window even if the CreateNoWindow property value is true or the WindowStyle property value is Hidden.&#8221;<br \/>\nAt the moment I&#8217;m not changing the user from the service, but executing the external program under the service account.<\/p>\n<p>I had also another small issue: since I was reading the password from an ini file, I thought the StartInfo:PasswordInClearText property was enough. On my development machine it worked, but crashed on the production server, an SBS 2011 (based on Windows Server 2008 R2) because with the .NET Framework 4 this property simply does not exists.<\/p>\n<p>Another issue: if you plan to start a process as another user from a service: this user needs local logon rights (on a server OS this is a manual change)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>These days, I was working on a webservice that worked directly with http.sys. This service was planned to wait for requests, and launch programs depending on the request. Firstly, I planned to use the local system account, and launch the external programs as specific user. This program should be started from a network share, using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5,23],"tags":[],"class_list":["post-230","post","type-post","status-publish","format-standard","hentry","category-visual-objects-programming","category-vulcan-net-programming","category-x-programming"],"_links":{"self":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/230","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=230"}],"version-history":[{"count":3,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions"}],"predecessor-version":[{"id":233,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=\/wp\/v2\/posts\/230\/revisions\/233"}],"wp:attachment":[{"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=230"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=230"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.riedmann.it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=230"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}