kashamalasha / nightscout-widget-electron

An Electron widget application to show on a desktop blood glucose value is getting from Nightscout API
https://github.com/kashamalasha/nightscout-widget-electron
GNU General Public License v3.0
33 stars 7 forks source link

[Bug]: exe closes, when started via batch file #100

Closed Tuphal closed 2 months ago

Tuphal commented 3 months ago

Contact Details

No response

What happened?

I'm using a batch file to start all programs after boot. As soon as the cmd-line windows is closed, Owlet is also closed.

Same happens, when I open Owlet.exe directly with cmd-line with the same start-cmd as from the batch file: start "" "C:/Apps/Owlet_Nightscout/Owlet.exe"

When opening the Owlet.exe by hand, it stays open. Is there any argument/parameter to pass, so that Owlet will stay open?

Steps to reproduce?

  1. Open cmd
  2. Start Owlet: start "" "C:/Apps/Owlet_Nightscout/Owlet.exe"
  3. Owlet starts
  4. Close cmd-line window
  5. Owlet is closed

Screenshot?

No response

Application version

0.8.2-beta (Latest)

What operating system are you seeing the problem on?

MS Windows

Operating system's version and architecture

Win 10 Pro 22H2 and Enterprise 22H2

Relevant log output or debug info

No response

kashamalasha commented 2 months ago

Hi! Running a program in the background from a batch file in Windows requires combining batch scripting with VBScript, as there is no direct way to hide the command prompt window using only batch commands.

You can achieve this by creating a temporary VBScript that runs your application and then hides the command prompt window. Here’s how you can do it:

@echo off
set appPath="C:\Users\Administrator\AppData\Local\Programs\nightscout-widget-electron\Owlet.exe"
set vbsScript="%temp%\invisible.vbs"
echo Set WshShell = CreateObject("WScript.Shell") > %vbsScript%
echo WshShell.Run %appPath%, 0 >> %vbsScript%
cscript //nologo %vbsScript%
del %vbsScript%

In this script:

Alternatively, you can use a VBScript or PowerShell script to achieve similar results. Batch scripting creates a synchronous process tied to the command window, which is why this additional scripting is necessary to hide the command prompt window.