{"id":1229,"date":"2022-10-10T08:18:58","date_gmt":"2022-10-10T08:18:58","guid":{"rendered":"https:\/\/www.nooblet.org\/blog\/?p=1229"},"modified":"2022-11-05T00:16:12","modified_gmt":"2022-11-05T00:16:12","slug":"vbscript-wrapper-for-powershell-scripts-to-hide-window","status":"publish","type":"post","link":"https:\/\/www.nooblet.org\/blog\/2022\/vbscript-wrapper-for-powershell-scripts-to-hide-window\/","title":{"rendered":"VBScript wrapper for PowerShell scripts to hide window"},"content":{"rendered":"<p>Even with PowerShell&#8217;s command-line argument &#8220;NoWindow&#8221;, a minimized powershell prompt is seen briefly by the user.<\/p>\n<p>Using VBScripts ability to load console applications completely hidden, we can run PowerShell without interrupting the user.<\/p>\n<p>The VBScript takes a single argument which is the filename of the powershell script. The VBScript needs to be in the same folder as the powershell script as it will work out its own scriptpath and use this to find the PowerShell script.<\/p>\n<pre class=\"lang:vb decode:true \" >Dim objShell,objFSO,objFile\r\n\r\nSet objShell = CreateObject(\"WScript.Shell\")\r\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\")\r\nSet objArgs = Wscript.Arguments\r\n\r\n' Get the VBS script full path and extrapolate its parent directory\r\nstrScriptPath = Wscript.ScriptFullName\r\nSet objScriptFile = objFSO.GetFile(strScriptPath)\r\nstrFolder = objFSO.GetParentFolderName(objScriptFile)\r\n\r\n' Take the string from arguments and prefix the parent directory\r\nstrPath = strFolder & \"\\\" & objArgs(0)\r\n\r\n'verify file exists\r\nIf objFSO.FileExists(strPath) Then\r\n  'return short path name\r\n  set objFile=objFSO.GetFile(strPath)\r\n  strCMD=\"powershell -nologo -executionpolicy bypass -command \" & Chr(34) & \"&{\" & objFile.ShortPath & \"}\" & Chr(34)\r\n\r\n  'use 0 to hide window\r\n  objShell.Run strCMD,0\r\n\r\nElse\r\n\r\n  'Display error message\r\n  WScript.Echo \"Failed to find \" & strPath\r\n  WScript.Quit\r\n\r\nEnd If<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Even with PowerShell&#8217;s command-line argument &#8220;NoWindow&#8221;, a minimized powershell prompt is seen briefly by the user. Using VBScripts ability to load console applications completely hidden, we can run PowerShell without interrupting the user. The VBScript takes a single argument which is the filename of the powershell script. The VBScript needs to be in the same [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":641,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1229","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-other"],"_links":{"self":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/1229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/comments?post=1229"}],"version-history":[{"count":2,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/1229\/revisions"}],"predecessor-version":[{"id":1231,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/posts\/1229\/revisions\/1231"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/media\/641"}],"wp:attachment":[{"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/media?parent=1229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/categories?post=1229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nooblet.org\/blog\/wp-json\/wp\/v2\/tags?post=1229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}