[GH-ISSUE #34] [BUG] Launcher.bat actually clears User's Path variable #11

Closed
opened 2026-10-15 18:06:09 +00:00 by bsakaguchi · 2 comments
Owner

Originally created by @The1stWii2 on GitHub (Feb 3, 2024).
Original GitHub issue: https://github.com/SillyTavern/SillyTavern-Launcher/issues/34

Originally assigned to: @deffcolony on GitHub.

Environment

Windows

System

Windows 11 - 23H2

Describe the problem

I noticed after using the Launcher, I noticed that quite a few of my programs broke. Investigating it, I realised my User Path variable was now empty! Using Process Monitor, I eventually found Silly Tavern Launcher to be the culprit.

The exact section is near the start, used to append paths to the current User Path, if they are missing,
github.com/SillyTavern/SillyTavern-Launcher@9241f92ae4/Launcher.bat (L110-L122)

The expected behaviour of the Launcher.bat Batch file is to append Winget current Path value, if it is not found and save it, however, due to Batch evaluation, the actual behaviour saves an empty string.

Additional info

Demo video

https://github.com/SillyTavern/SillyTavern-Launcher/assets/109736937/7a519c0d-2fb9-4bff-ab1e-36f929a0ef15

The bug originates from not accounting for Batch evaluates variables in brackets. Batch performs replacement before execution, so new_path is never set when it is used. You can try this with the following snippet:

@echo off

if 1 neq 0 (
    set foo=test
    rem Expect 'foo' to be 'test'
    echo '%foo%'
)
exit
Snippet demo

image

The correct way would be to use setlocal enabledelayedexpansion and replace any %var%s which are assigned a value within blocks with !var!, like so:

setlocal enabledelayedexpansion

[...]

rem Append the new paths to the current PATH only if they don't exist
if %ff_path_exists% neq 0 (
    set "new_path=%current_path%;%winget_path%"
    ECHO "current_path is '%current_path%'"
    ECHO "winget_path is '%winget_path%'"
    ECHO "new_path is '!new_path!'"

    rem Update the PATH value in the registry
    reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f

    rem Update the PATH value for the current session
    setx PATH "!new_path!" > nul
    echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%winget added to PATH.%reset%
) else (
    set "new_path=%current_path%"
    echo %blue_fg_strong%[INFO] winget already exists in PATH.%reset%
)
ECHO "USER'S PATH WAS JUST UPDATED CORRECTLY!"
PAUSE

image

This bug probably also exists in other areas, causing other problems, but this is probably the most crucial one to fix.

Please tick the boxes

Originally created by @The1stWii2 on GitHub (Feb 3, 2024). Original GitHub issue: https://github.com/SillyTavern/SillyTavern-Launcher/issues/34 Originally assigned to: @deffcolony on GitHub. ### Environment Windows ### System Windows 11 - 23H2 ### Describe the problem I noticed after using the Launcher, I noticed that quite a few of my programs broke. Investigating it, I realised my User Path variable was now empty! Using Process Monitor, I eventually found Silly Tavern Launcher to be the culprit. The exact section is near the start, used to append paths to the current User Path, if they are missing, https://github.com/SillyTavern/SillyTavern-Launcher/blob/9241f92ae454f33ca9c018540d1261684354c02c/Launcher.bat#L110-L122 The expected behaviour of the `Launcher.bat` Batch file is to append Winget current Path value, if it is not found and save it, however, due to Batch evaluation, the actual behaviour saves an empty string. ### Additional info <details> <summary>Demo video</summary> https://github.com/SillyTavern/SillyTavern-Launcher/assets/109736937/7a519c0d-2fb9-4bff-ab1e-36f929a0ef15 </details> The bug originates from not accounting for Batch evaluates variables in brackets. Batch performs replacement *before* execution, so `new_path` is never set when it is used. You can try this with the following snippet: ```Batch @echo off if 1 neq 0 ( set foo=test rem Expect 'foo' to be 'test' echo '%foo%' ) exit ``` <details> <summary>Snippet demo</summary> ![image](https://github.com/SillyTavern/SillyTavern-Launcher/assets/109736937/4c890870-445b-4609-a0f3-1c11c92606d6) </details> The correct way would be to use `setlocal enabledelayedexpansion` and replace any `%var%`s which are assigned a value within blocks with `!var!`, like so: ```Batch setlocal enabledelayedexpansion [...] rem Append the new paths to the current PATH only if they don't exist if %ff_path_exists% neq 0 ( set "new_path=%current_path%;%winget_path%" ECHO "current_path is '%current_path%'" ECHO "winget_path is '%winget_path%'" ECHO "new_path is '!new_path!'" rem Update the PATH value in the registry reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "!new_path!" /f rem Update the PATH value for the current session setx PATH "!new_path!" > nul echo %blue_bg%[%time%]%reset% %blue_fg_strong%[INFO]%reset% %green_fg_strong%winget added to PATH.%reset% ) else ( set "new_path=%current_path%" echo %blue_fg_strong%[INFO] winget already exists in PATH.%reset% ) ECHO "USER'S PATH WAS JUST UPDATED CORRECTLY!" PAUSE ``` ![image](https://github.com/SillyTavern/SillyTavern-Launcher/assets/109736937/dd1c54a6-57cc-4f06-9233-038128ba602a) This bug probably also exists in other areas, causing other problems, but this is probably the most crucial one to fix. ### Please tick the boxes - [X] You have explained the issue clearly, and included all relevant info - [X] You've checked that this [issue hasn't already been raised](https://github.com/SillyTavern/SillyTavern-Launcher/issues?q=is%3Aissue) - [X] You've checked the [docs](https://docs.sillytavern.app/) ![important](https://img.shields.io/badge/Important!-F6094E)
Author
Owner

@deffcolony commented on GitHub (Feb 4, 2024):

@The1stWii2
I fixed the bug in: github.com/SillyTavern/SillyTavern-Launcher@998070dbc5
Please update the launcher
Let me know if the problem still occurs (I did test it)

<!-- gh-comment-id:1925924260 --> @deffcolony commented on GitHub (Feb 4, 2024): @The1stWii2 I fixed the bug in: https://github.com/SillyTavern/SillyTavern-Launcher/commit/998070dbc5f8a7948f87555bfd6d35384418e559 Please update the launcher Let me know if the problem still occurs (I did test it)
Author
Owner

@The1stWii2 commented on GitHub (Feb 4, 2024):

Just tested.
Seems to work as intended now.

<!-- gh-comment-id:1925952449 --> @The1stWii2 commented on GitHub (Feb 4, 2024): Just tested. Seems to work as intended now.
Sign in to join this conversation.
No description provided.