{"id":1575,"date":"2014-04-19T00:01:00","date_gmt":"2014-04-19T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/04\/19\/weekend-scripter-use-powershell-to-hide-processes-in-windows\/"},"modified":"2014-04-19T00:01:00","modified_gmt":"2014-04-19T00:01:00","slug":"weekend-scripter-use-powershell-to-hide-processes-in-windows","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-use-powershell-to-hide-processes-in-windows\/","title":{"rendered":"Weekend Scripter: Use PowerShell to Hide Processes in Windows"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to easily hide processes in Windows.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. One of the things I used to have problems with when I was a network administrator, was running scripts on systems without a text box demanding attention from the user. In fact, the power users quickly discovered that if they simply clicked the big X button, they could exempt themselves from my scripts. I soon found out that there was a program I could use to hide the dialogs from the users. It worked, but the program was expensive, and it required a per-user license mode.<\/p>\n<p>I was recently in Amsterdam at the Dutch PowerShell User Group meeting. (They actually had four Windows PowerShell MVPs in attendance, including the Scripting Wife). A question came up from one of the attendees about hiding processes. I was quickly taken back to my time as a net admin. But now with Windows PowerShell, it is easy.<\/p>\n<h2>Hiding in plain sight<\/h2>\n<p>One of the cool things about Windows PowerShell is that it has a number of built-in cmdlets for working with processes. To find these, I use the <b>Get-Command<\/b> cmdlet, and look for a <strong>Noun<\/strong> of <b>process<\/b>:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-Command -Noun process<\/p>\n<p style=\"margin-left:30px\">CommandType&nbsp;&nbsp;&nbsp;&nbsp; Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.PowerShel&#8230;<\/p>\n<p>From the list, I can see that the cmdlet I want might be <b>Start-Process<\/b>. So, I use the <b>Get-Help<\/b> cmdlet to see if my guess is correct.<\/p>\n<p style=\"margin-left:30px\"><b>Note<\/b> &nbsp;In Windows PowerShell 3.0 and later, make sure that you open Windows PowerShell with Admin rights, and use the <b>Update-Help<\/b> cmdlet to ensure you have access to the latest Help content.<\/p>\n<p>I use the <b>Get-Help<\/b> cmdlet to look at information about the <b>Start-Process<\/b> cmdlet. As shown in the following image, I see that a number of switches and parameters are available, and one is the <b>&ndash;WindowStyle<\/b> parameter.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-4-19-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-4-19-14-01.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Unfortunately, I am not sure what I can specify for a window style. So I use one of my favorite tricks. I give the parameter a bogus value, and look at the error message that returns. This technique is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-4-19-14-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-4-19-14-02.png\" alt=\"Image of error message\" title=\"Image of error message\" \/><\/a><\/p>\n<p>Now, I see that I can use <b>Minimized<\/b> as a parameter value.<\/p>\n<p style=\"margin-left:30px\"><b>Note&nbsp;<\/b> Keep in mind that in Windows PowerShell 4.0, I can use tab expansion to bring up the available options for a parameter.<\/p>\n<p>The command is shown here:<\/p>\n<p style=\"margin-left:30px\">Start-Process notepad -WindowStyle Hidden<\/p>\n<p>No output appears in the Windows PowerShell console. Also, no new icon shows up on the tool bar. There is no indication that the process is running.<\/p>\n<p>I can use the <b>Get-Process<\/b> cmdlet as shown here to retrieve the process:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-4-19-14-03.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-4-19-14-03.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>Cool, now that I can find the process, I can also terminate the process. To do this, I pipe the returned process object to the <b>Stop-Process<\/b> cmdlet:<\/p>\n<p style=\"margin-left:30px\">Get-Process notepad | Stop-Process<\/p>\n<p>Neat. Now I can start a process hidden (or use any of the other Windows styles, such as minimized) if I need to do so.<\/p>\n<p>Hope you have a great weekend.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to easily hide processes in Windows. Microsoft Scripting Guy, Ed Wilson, is here. One of the things I used to have problems with when I was a network administrator, was running scripts on systems without a text box demanding attention from the user. In [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[31,87,2,3,4,61,45],"class_list":["post-1575","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-operating-system","tag-processes","tag-running","tag-scripting-guy","tag-scripting-techniques","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to easily hide processes in Windows. Microsoft Scripting Guy, Ed Wilson, is here. One of the things I used to have problems with when I was a network administrator, was running scripts on systems without a text box demanding attention from the user. In [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1575"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1575\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}