TroubleChute Logo
< Go Back

TroubleChute Script Hub

Currently viewing: PowerShell/General/scriptlauncher.ps1

NOTE: The following code may be out-of-date compared to GitHub, but is all pulled from GitHub every hour or so.

When shortlinks are used (filename as subdomain), code used by PowerShell and other interactions with this site is served from GitHub.

(Right-click -> Download the button below to save the file)

Last modified: 2023-05-31T22:17:18.000+02:00

# Copyright (C) 2023 TroubleChute (Wesley Pyburn)
# Licensed under the GNU General Public License v3.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see .
# ----------------------------------------
# This is a rather advanced little launcher.
# It runs the program, as requested, but it also handles Python errors, assuming a module is not found (didn't install properly) it tries again.
# NOTE: This can't automatically re-run the one-line installer command as that usually requires admin.
# ----------------------------------------

$Host.UI.RawUI.WindowTitle = '%PROGRAMNAME%'

Write-Host "-----------------------------------------" -ForegroundColor Cyan
Write-Host "TroubleChute %PROGRAMNAME% One-Line Launcher" -ForegroundColor Cyan
Write-Host " &" -ForegroundColor Cyan
Write-Host "-----------------------------------------" -ForegroundColor Cyan

Write-Host "Launching %PROGRAMNAME%..." -ForegroundColor Cyan


# Try run the program

Write-Host "`n--------------------------------" -ForegroundColor Cyan
Write-Host "TroubleChute One-Line installer:" -ForegroundColor Cyan
Write-Host "--------------------------------" -ForegroundColor Cyan
if ($LASTEXITCODE -eq 1){
    Write-Host "Python exited with an error code." -ForegroundColor Red
    do {
        Write-Host -ForegroundColor Cyan -NoNewline "Did you see something about 'ModuleNotFoundError' above? (y/n): "
        $reinstall = Read-Host
    } while ($reinstall -notin "Y", "y", "N", "n")

    if ($reinstall -in "Y", "y") {
        Write-Host "Reinstalling required packages..." -ForegroundColor Cyan

        Write-Host "`n`nIf you see any errors about 'access' in installing required packages above, please run this program as Administrator." -ForegroundColor Cya
        Write-Host "`nTrying to launch again!`nAssuming you get another ModuleNotFound error consider running the one-line installer again or contacting the software's developer.`n--------------------------------`n" -ForegroundColor Cyan

    } else {
        Write-Host "Exiting..." -ForegroundColor Cyan

TCNO TechNobo / TroubleChute © Wesley Pyburn (TroubleChute)
Support Me Privacy Policy Cookies Policy Terms of Service Contact