{"id":11425,"date":"2022-08-15T06:29:34","date_gmt":"2022-08-15T13:29:34","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=11425"},"modified":"2022-08-15T06:29:34","modified_gmt":"2022-08-15T13:29:34","slug":"trouble-running-batch-file","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/trouble-running-batch-file\/","title":{"rendered":"Q&#038;A: Why can&#8217;t AlwaysUp run my Batch File?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/qa-trouble-running-script-as-service.webp\" style=\"margin-bottom:20px;\" title=\"Why can't AlwaysUp run my Batch File?\" alt=\"Why can't AlwaysUp run my Batch File?\" border=\"0\" width=\"380\" height=\"160\" \/><\/div>\n<div class=\"blog-qa-question-box\">\n<img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"https:\/\/cdn.coretechnologies.com\/images\/quotes-transparent-21x21.webp\" width=\"21\" height=\"21\" \/>&nbsp;&nbsp;Hi. I think I&#8217;ve written a batch file that your <a href=\"\/products\/AlwaysUp\/\">AlwaysUp<\/a> software cannot run as a service.<\/p>\n<p>Here are the contents of my file:<\/p>\n<div class=\"code-box\">\n@echo off<br \/>\n> usermessage.vbs ECHO Set wshShell = CreateObject( &#8220;WScript.Shell&#8221; )<br \/>\n>>usermessage.vbs ECHO wshShell.Popup &#8220;My Text line 1&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 2&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 3&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 4&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 5&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 6&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 7&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 8&#8221; ^&#038; vbCrLf ^&#038; _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Text line 9&#8221;, 120, _<br \/>\n>>usermessage.vbs ECHO                &#8220;My Window Title&#8221;, 64<br \/>\nWSCRIPT.EXE usermessage.vbs<br \/>\nDEL usermessage.vbs\n<\/div>\n<p>I searched the internet for hours using various terms and finally found a suggestion that your software would solve my problem.<\/p>\n<p>It runs perfectly if I just click on it. But I could not make it run as a service. I&#8217;m not a pro at this.<\/p>\n<p>Any Ideas?<\/p>\n<p align=\"right\">&mdash; John<\/p>\n<\/div>\n<p>Hi John. Thanks for trying AlwaysUp and for getting in touch.<\/p>\n<h2 class=\"blog-caption\">What&#8217;s the batch file doing?<\/h2>\n<p>We&#8217;re not <a href=\"https:\/\/en.wikipedia.org\/wiki\/VBScript\" target=\"_blank\" rel=\"noopener\">VBScript<\/a> experts so it took us a while to understand what your batch file is doing!<\/p>\n<p>However, it soon became clear that the batch file:<\/p>\n<ol style=\"margin-bottom:24px\">\n<li>\n<p>Constructs a VBScript file named <b>usermessage.vbs<\/b> on the fly.<\/p>\n<\/li>\n<li>\n<p>Adds a line to usermessage.vbs to create a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Windows_Script_Host\" target=\"_blank\" rel=\"noopener\">Windows Script<\/a> shell object.<\/p>\n<\/li>\n<li>\n<p>Adds lines to usermessage.vbs that call the <a href=\"https:\/\/www.vbsedit.com\/html\/f482c739-3cf9-4139-a6af-3bde299b8009.asp\" target=\"_blank\" rel=\"noopener\">Popup<\/a> function with several lines of text.<\/p>\n<\/li>\n<li>\n<p>Runs usermessage.vbs, which shows a popup window with the specified text. The popup will stay on screen for up to 120 seconds, or until the user clicks the OK button.<\/p>\n<\/li>\n<li>\n<p>Deletes the usermessage.vbs file.<\/p>\n<\/li>\n<\/ol>\n<p>In summary, the purpose of the batch file is to show this message box for up to 2 minutes:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/popup-from-batch-file.png\" class=\"zoomPopup\" title=\"The batch file shows a popup\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/popup-from-batch-file.png\" title=\"The batch file shows a popup (click to enlarge)\" alt=\"The batch file shows a popup\" border=\"0\" \/><\/a><\/div>\n<p>It seems a bit contrived, but perhaps this code is a sample you created for testing? No doubt your &#8220;real&#8221; code is more practical and exciting. <font size=\"+1\">\ud83d\ude42<\/font><\/p>\n<h2 class=\"blog-caption\">AlwaysUp runs your batch file properly<\/h2>\n<p>AlwaysUp launches the batch file as a Windows Service just fine. And it has no problem running the dynamically created VBScript file either. We&#8217;re lucky to have hundreds of customers using AlwaysUp to launch their batch files, every day.<\/p>\n<p>Indeed, we were able to setup your batch file in AlwaysUp and confirm that it runs as expected. <a href=\"\/blog\/windows-services\/essential-tools-for-windows-services-process-explorer\/\">Process Explorer<\/a> showed AlwaysUp running the batch file, which launched the Windows Script Host executable (wscript.exe) to display the popup window. You can see this arrangement in the tree of processes on the left:<\/p>\n<div align=\"center\"><a href=\"\/blog\/images\/alwaysup-running-popup-batch-file.png\" class=\"zoomPopup\" title=\"AlwaysUp running the batch file as a Windows Service\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"image-padding\" src=\"\/blog\/images\/alwaysup-running-popup-batch-file.png\" title=\"AlwaysUp running the batch file as a Windows Service (click to enlarge)\" alt=\"AlwaysUp running the batch file as a Windows Service\" border=\"0\" width=\"520\" \/><\/a><\/div>\n<p>All good, right? Well, not entirely&#8230;<\/p>\n<h2 class=\"blog-caption\">Session 0 Isolation prevents you from seeing the popup window<\/h2>\n<p>Even though your script is running, you will not be able to see the popup window on your desktop. That is because of <a href=\"https:\/\/www.coretechnologies.com\/WindowsServices\/FAQ.html#WhatIsSession0Isolation\">Session 0 Isolation<\/a> &mdash; an important security measure that constrains Windows Services.<\/p>\n<p>You won&#8217;t see the popup because:<\/p>\n<ol style=\"margin-bottom:24px\">\n<li>\n<p><b>your batch file is running in Session 0<\/b>, on the special background desktop where all Windows Services operate, and<\/p>\n<\/li>\n<li>\n<p><b>Windows isolates applications running in Session 0<\/b>, meaning that they cannot show up alongside the other windows on your screen.<\/p>\n<\/li>\n<\/ol>\n<p>Once upon a time, you were be able to <a href=\"\/products\/SwitchToSession0\/\">switch to Session 0<\/a> to see the popup but no longer. Unfortunately, Microsoft <a href=\"\/blog\/windows-services\/interactive-services-removed-windows-10\/\">removed that capability<\/a> a few years ago. As a result, there is no way to see a window displayed in Session 0.<\/p>\n<p>So in summary, your batch file will not pop up a window on your interactive desktop when you run it as a Windows Service. And that&#8217;s true even if you don&#8217;t use AlwaysUp because <b>the restriction is built into Windows itself<\/b>.<\/p>\n<p>I hope this makes sense. Unfortunately, Session 0 Isolation can be tricky to comprehend. Please check out these FAQ entries if you want to dig into the details (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Caveat_emptor\" target=\"_blank\" rel=\"noopener\">caveat emptor<\/a>):<\/p>\n<ul style=\"margin-bottom:24px\">\n<li>\n<p><a href=\"\/WindowsServices\/FAQ.html#WhatIsSession0Isolation\">What is Session 0 Isolation?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"\/products\/AlwaysUp\/AlwaysUp_FAQ.html#SessionZeroIsolation\">Why don&#8217;t my application&#8217;s windows or task-tray icons show up?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"\/WindowsServices\/FAQ.html#GUIServices\">Can a Windows Service have a GUI? Should a Windows Service have a GUI?<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"\/WindowsServices\/FAQ.html#StartGUIApplication\">Can a Windows Service start a GUI application?<\/a><\/p>\n<\/li>\n<\/ul>\n<p>And please be sure to <a href=\"\/support\/\">get in touch<\/a> if you have any other questions.<\/p>\n<p>Best of luck with your project!<\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/srvany\/top-3-srvany-problems\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"The Top 3 Real-World Problems with Microsoft Srvany\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/service-caution-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">The Top 3 Real-World Problems with Microsoft Srvany<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/service-start-time\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"When did my Windows Service Start?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/windows-service-uptime-thumbnail.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">When did my Windows Service Start?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/troubleshoot-alwaysup-command-prompt\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"AlwaysUp not Starting your Application? Troubleshoot with the Command Prompt\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/command-prompt-150x150.jpg\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">AlwaysUp not Starting your Application? Troubleshoot with the Command Prompt<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;Hi. I think I&#8217;ve written a batch file that your AlwaysUp software cannot run as a service. Here are the contents of my file: @echo off > usermessage.vbs ECHO Set wshShell = CreateObject( &#8220;WScript.Shell&#8221; ) >>usermessage.vbs ECHO wshShell.Popup &#8220;My Text &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/trouble-running-batch-file\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":11429,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[26,44,127,153,294,196],"class_list":["post-11425","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-alwaysup-tag","tag-batch-file","tag-qa","tag-session-0-isolation","tag-vbscript","tag-windows-services-2"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/11425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=11425"}],"version-history":[{"count":14,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/11425\/revisions"}],"predecessor-version":[{"id":11444,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/11425\/revisions\/11444"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/11429"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=11425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=11425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=11425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}