Converting .bat file to MacOS [closed] - bash

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 days ago.
Improve this question
I need some help converting a .bat executable file that I run on my PC at my job so that it works on a Mac. I am taking a Basic Scripting class and when I'm home I cannot test the scripts I write until I get to work. I want to be able to write scripts in Bash and Powershell. Below is the menu script I wrote that I would like to translate to Bash.
#ECHO OFF
C:
CD\
CLS
:MENU
CLS
ECHO ============= ROBBIE’S MENU =============
ECHO -------------------------------------
ECHO 1. OPEN CALCULATOR
ECHO 2. OPEN WORDPAD
ECHO 3. OPEN CONTROL PANEL
ECHO 4. OPEN DEVICE MANAGER
ECHO 5. OPEN GOOGLE WEBPAGE
ECHO 6. OPEN AMAZON WEBPAGE
ECHO -------------------------------------
ECHO -------------------------------------
ECHO ==========PRESS 'Q' TO QUIT==========
ECHO.
SET INPUT=
SET /P INPUT=Please select a number:
IF /I '%INPUT%'=='1' GOTO CALCULATOR
IF /I '%INPUT%'=='2' GOTO WORDPAD
IF /I '%INPUT%'=='3' GOTO CONTROLPANEL
IF /I '%INPUT%'=='4' GOTO DEVICEMNGR
IF /I '%INPUT%'=='5' GOTO GOOGLE
IF /I '%INPUT%'=='6' GOTO AMAZON
IF /I '%INPUT%'=='Q' GOTO Quit
CLS
ECHO ============INVALID INPUT============
ECHO -------------------------------------
ECHO Please select a number from the Main
echo Menu [1-6] or select 'Q' to quit.
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO MENU
:CALCULATOR
cd %windir%\system32\calc.exe
start calc.exe
GOTO MENU
:WORDPAD
cd %windir%\system32\wordpad.exe
start wordpad.exe
GOTO MENU
:CONTROLPANEL
cd %windir%\system32\control.exe
start control.exe
GOTO MENU
:DEVICEMNGR
cd %windir%\system32\devmgmt.msc
start devmgmt.msc
GOTO MENU
:GOOGLE
start explorer https://www.google.com
GOTO MENU
:AMAZON
start explorer https://www.amazon.com
GOTO MENU
:Quit
CLS
ECHO ==============THANKYOU===============
ECHO -------------------------------------
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE>NUL
EXIT
I tried this and it work in the cmd on Windows but I need help translating to Bash.

Related

Converting CMD script to GUI [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
I have a question.
I'm currently trying to convert a simple batch script that I have made to a GUI-version. I'm not a professional, but I love to tinker around and try stuff out.
Is there anyone who could help me to go in the right direction?
Here is my simple batch script:
#echo off
::BatchHasAdmin
:-------------------------------------
REM --> Check if this file has administrator rights.
IF "%PROCESSOR_ARCHITECTURE%" EQU "amd64" (
>nul 2>&1 "%SYSTEMROOT%\SysWOW64\cacls.exe" "%SYSTEMROOT%\SysWOW64\config\system"
) ELSE (
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
)
REM --> If no rights, we don't have setted the flag for it.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params= %*
echo UAC.ShellExecute "cmd.exe", "/c ""%~s0"" %params:"=""%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
:: MainCode
#echo off
title pcHealth - Check your PC's Health! - version 1.5.7-beta
cd /
color D
cls
:MENU
cls
color D
echo.
echo Thanks for downloading and using pcHealth!
echo Please be sure that you are running this Batch file in Administrator mode.
echo.
echo Made by REALSDEALS - Licensed under GNU-3 (You are free to use, but not to change or to remove this line.)
echo You are now using version 1.5.7 (Beta)
echo.
echo %DATE%, %TIME%
echo.
echo ...........................................................
echo Enter number 1 to open a menu regarding testing scripts.
echo Enter number 2 to open a menu regarding programs for testing /w downloadable redirects.
echo Enter number 3 to go to the repository of pcHealth.
echo Enter number 4 to close this batch script.
echo ...........................................................
echo.
SET /P A=Type one of the numbers from the menu above to open the desired menu and then press ENTER. Enter:
IF %A%==1 GOTO TOOLS
IF %A%==2 GOTO PROGRAMS
IF %A%==3 GOTO PCHEALTHGETVER
IF %A%==4 GOTO CLOSE
:TOOLS
cls
color 9
echo.
echo ...........................................................
echo Enter number 1 to gather generic information about the system.
echo Enter number 2 to see which CPU and GPU are in the system.
echo Enter number 3 to run a system scan for missing/corrupt files.
echo Enter number 4 to try and repair missing/corrupt files.
echo Enter number 5 to run a system scan and to start an attempt on repairing missing/corrupt files.
echo Enter number 6 to generate a battery report. (Laptop only)
echo Enter number 7 to open the GUI to Windows Updates.
echo Enter number 8 to start a short ping test.
echo Enter number 9 to start a continues ping test.
echo Enter number 10 to update system programs.
echo Enter number 11 to re-start the audio drivers of your system.
echo Enter number 12 to re-open the generated battery report file.
echo Enter number 13 to re-open the CBS.log (AKA DISM.log)
echo Enter number 14 to get your Ninite! Includes Edge, Chrome, VLC and 7Zip.
echo Enter number 15 to see your systems Windows License key.
echo Enter number 16 BIOS Password Recovery.
echo Enter number 17 to shutdown, reboot or log off from your PC/laptop.
echo Enter number 18 to open the programs menu.
echo Enter number 19 to return to the previous menu.
echo Enter number 20 to close this batch file.
echo ...........................................................
echo.
SET /P B=Type one of the numbers from the menu above to run the desired function, then press ENTER. Enter:
IF %B%==1 GOTO SYSINFO
IF %B%==2 GOTO CPUANDGPUINFO
IF %B%==3 GOTO SCAN
IF %B%==4 GOTO DISM
IF %B%==5 GOTO SCSM
IF %B%==6 GOTO BATTERY
IF %B%==7 GOTO UPDATE
IF %B%==8 GOTO SHORTPING
IF %B%==9 GOTO CONTINUESPING
IF %B%==10 GOTO SYSUPDATE
IF %B%==11 GOTO AUDIORE
IF %B%==12 GOTO BATOPEN
IF %B%==13 GOTO OPENCBSLOG
IF %B%==14 GOTO NINITE
IF %B%==15 GOTO LICENSE
IF %B%==16 GOTO BIOSPW
IF %B%==17 GOTO RESHUT
IF %B%==18 GOTO PROGRAMS
IF %B%==19 GOTO MENU
IF %B%==20 GOTO CLOSE
:PROGRAMS
cls
color B
echo.
echo ...........................................................
echo Enter number 1 to get hardware info.
echo Enter number 2 to get ADW Cleaner.
echo Enter number 3 to get DiskInfo64.
echo Enter number 4 to get DiskMark64.
echo Enter number 5 to get Prime95.
echo Enter number 6 to open the tools menu.
echo Enter number 7 to return to the previous menu.
echo Enter number 8 to close the script.
echo ...........................................................
echo.
SET /P AB=Type one of the numbers above to run the desired function. Enter:
IF %AB%==1 GOTO HARDINFODOWN
IF %AB%==2 GOTO ADWCLEANER
IF %AB%==3 GOTO DISKINFODOWN
IF %AB%==4 GOTO DISKMARKDOWN
IF %AB%==5 GOTO PRIMEDOWN
IF %AB%==6 GOTO TOOLS
IF %AB%==7 GOTO MENU
IF %AB%==8 GOTO CLOSE
:SYSUPDATE
cls
color A
winget upgrade --all
pause
echo.
SET /P LL=Enter number 1 to return to the sub-menu, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %LL%==1 GOTO TOOLS
IF %LL%==2 GOTO MENU
IF %LL%==3 GOTO CLOSE
:SYSINFO
cls
color A
systeminfo
pause
echo.
SET /P C=Enter number 1 to return to the main-menu, enter number 2 to go back to the previous sub-menu or enter number 3 to close the script. Enter:
IF %C%==1 GOTO MENU
IF %C%==2 GOTO TOOLS
IF %C%==3 GOTO CLOSE
:SCAN
cls
color A
sfc /scannow
pause
echo.
SET /P D=If the scan found any corrupt files, enter number 1 to check the .log, enter number 2 to return to the previous sub-menu, enter number 3 when you want to return to the menu or enter number 4 to close the script. Enter:
IF %D%==1 GOTO OPENCBSLOG
IF %D%==2 GOTO TOOLS
IF %D%==3 GOTO MENU
IF %D%==4 GOTO CLOSE
:CPUANDGPUINFO
cls
color A
echo.
echo Your CPU information:
echo.
wmic cpu get caption, deviceid, name, numberofcores, maxclockspeed, status
echo.
echo Your GPU information:
echo.
wmic path win32_VideoController get name
pause
echo.
SET /P E=Enter number 1 to return to the main-menu, enter number 2 to go back to the previous sub-menu or enter number 3 to close the script. Enter:
IF %E%==1 GOTO MENU
IF %E%==2 GOTO TOOLS
IF %E%==3 GOTO CLOSE
:DISM
cls
color A
DISM /online /cleanup-image /checkhealth
DISM /online /cleanup-image /scanhealth
pause
echo.
SET /P F=Enter number 1 to start an attempt on repairing, enter number 2 to return to the previous sub-menu, number 3 for the main-menu or number 4 to exit the script. Enter:
IF %F%==1 GOTO DISMRESTORE
IF %F%==2 GOTO TOOLS
IF %F%==3 GOTO MENU
IF %F%==4 GOTO CLOSE
:DISMRESTORE
cls
color A
DISM /online /cleanup-image /restorehealth
pause
echo.
SET /P G=Enter number 1 to return to the main-menu, enter number 2 to go back to the previous sub-menu or enter number 3 to close the script. Enter:
IF %G%==1 GOTO MENU
IF %G%==2 GOTO TOOLS
IF %G%==3 GOTO CLOSE
:SCSM
cls
color A
sfc /scannow
pause
echo.
SET /P H=If the scan found any corrupt files, enter number 1 to check the .log, enter number 2 to start an attempt to repair the corrupt/missing files,enter number 3 to return to the previous sub-menu, enter number 4 to return to the main-menu or enter number 5 to exit the script. Enter:
IF %H%==1 GOTO SCSMOPENLOG
IF %H%==2 GOTO CONTINUE
IF %H%==3 GOTO TOOLS
IF %H%==4 GOTO MENU
IF %H%==5 GOTO CLOSE
:SCSMOPENLOG
cls
color A
start %windir%\explorer.exe "C:\Windows\Logs\CBS\CBS.log"
pause
echo.
SET /P I=Enter number 1 to start an attempt to repair the corrupt/missing files, if any are found... Enter number 2 to return to the previous sub-menu, enter number 3 to return to the main-menu or enter number 4 to exit the script. Enter:
IF %I%==1 GOTO CONTINUE
IF %I%==2 GOTO TOOLS
IF %I%==3 GOTO MENU
IF %I%==4 GOTO CLOSE
:CONTINUE
cls
color A
DISM /online /cleanup-image /checkhealth
DISM /online /cleanup-image /scanhealth
pause
DISM /online /cleanup-image /restorehealth
pause
echo.
SET /P J=Enter number 1 to return to the previous sub-menu, enter number 2 to return to the main-menu or enter number 3 to exit. Enter:
IF %J%==1 GOTO TOOLS
IF %J%==2 GOTO MENU
IF %J%==3 GOTO CLOSE
:BATTERY
cls
color A
powercfg /batteryreport
pause
echo.
SET /P K=Enter number 1 to open the generated file, enter number 2 to return to the previous sub-menu, number 3 to return to the main-menu or enter number 4 to exit the script. Enter:
IF %K%==1 GOTO BATOPEN
IF %K%==2 GOTO TOOLS
IF %K%==3 GOTO MENU
IF %K%==4 GOTO CLOSE
:UPDATE
cls
color A
control update
pause
echo.
SET /P L=Enter number 1 to return to the previous sub-menu, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %L%==1 GOTO TOOLS
IF %L%==2 GOTO MENU
IF %L%==3 GOTO CLOSE
:SHORTPING
cls
color A
ping 8.8.8.8
pause
echo.
SET /P M=Enter number 1 to return to the previous sub-menu, enter number 2 to return to the main-menu, enter number 3 to start a continues ping test or enter number 4 to exit the script. Enter:
IF %M%==1 GOTO TOOLS
IF %M%==2 GOTO MENU
IF %M%==3 GOTO CONTINUESPING
IF %M%==4 GOTO CLOSE
:CONTINUESPING
cls
color A
ping 8.8.8.8 -t -l 256
pause
echo.
SET /P N=Enter number 1 to return to the previous sub-menu menu, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %N%==1 GOTO TOOLS
IF %N%==2 GOTO MENU
IF %N%==2 GOTO CLOSE
:AUDIORE
cls
color A
if "%1"=="am_admin" (powershell start -verb runas '%0' am_admin)
net stop audiosrv
net stop AudioEndPointBuilder
net start AudioEndPointBuilder
net start audiosrv
echo.
echo Your audio drivers have been reset, hope it solved your audio problem!
echo.
pause
GOTO TOOLS
:BATOPEN
cls
color A
start %windir%\explorer.exe "C:\battery-report.html"
pause
echo.
SET /P O=Enter number 1 to return to the previous sub-menu, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %O%==1 GOTO TOOLS
IF %O%==2 GOTO MENU
IF %O%==3 GOTO CLOSE
:OPENCBSLOG
cls
color A
start %windir%\explorer.exe "C:\Windows\Logs\CBS\CBS.log"
pause
echo.
SET /P P=Enter number 1 to return to the previous sub-menu, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %P%==1 GOTO TOOLS
IF %P%==2 GOTO MENU
IF %P%==3 GOTO CLOSE
:NINITE
cls
color A
start "" https://ninite.com/7zip-chrome-edge-vlc/ninite.exe
pause
echo.
SET /P Q=Enter number 1 to return to the previous sub-menu, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %Q%==1 GOTO TOOLS
IF %Q%==2 GOTO MENU
IF %Q%==3 GOTO CLOSE
:LICENSE
cls
color A
echo.
echo "Your systems license key:"
wmic path SoftwareLicensingService get OA3xOriginalProductKey
pause
color E
echo.
echo If it didn't showed a key, it is possible that this PC is using a 'illegal' key, or a key that was used for a previous installation of Windows 7/8 - then upgraded to 10/11.
echo.
echo You can also try to use a different script for the license key, you can find it in the 'Scripts' folder in this pcHealth folder!
echo.
SET /p R=If you want to return to the previous sub-menu, enter number 1. To return to the main-menu, enter number 2. To exit the script, enter the number 3. Enter:
IF %R%==1 GOTO TOOLS
IF %R%==2 GOTO MENU
IF %R%==2 GOTO CLOSE
:BIOSPW
cls
color E
echo.
echo The BIOS Password Recovery tool is a website that can be used to gather/generate a recovery code for the BIOS.
echo.
echo If you don't know how to use this function/website, then
echo I would suggest that you enter '2' on the next line to learn more.
echo.
echo The credits for this function and repository goes to the owner: #bacher09
echo.
SET /P SK=Enter number 1 to visit the website, enter number 2 to go to the repository of BIOS-PW and learn more! Enter number 3 to return to the sub-menu, enter number 4 to return to the main-menu or enter number 5 to close the script. Enter:
IF %SK%==1 start "" https://bios-pw.org && GOTO BIOSPW
IF %SK%==2 start "" https://github.com/bacher09/pwgen-for-bios && GOTO BIOSPW
IF %SK%==3 GOTO TOOLS
IF %SK%==4 GOTO MENU
IF %SK%==5 GOTO CLOSE
:RESHUT
cls
color A
echo.
SET /P S=If you want to log off from your PC/Laptop enter number 1, to restart enter number 2, to shutdown enter number 3 and to return to the previous sub-menu enter number 4 or to exit the script... enter number 5. Enter:
IF %S%==1 GOTO LOGOFF1
IF %S%==2 GOTO RESTART2
IF %S%==3 GOTO SHUTDOWN3
IF %S%==4 GOTO TOOLS
IF %S%==5 GOTO CLOSE
:LOGOFF1
cls
color A
echo.
SET /P T=Are you sure that you want to log off your PC? Enter number 1, enter number 2 to return to the previous sub-menu, enter number 3 to return to the main-menu or enter number 4 to exit the script. Enter:
IF %T%==1 GOTO LOGOFFCONFIRM1
IF %T%==2 GOTO TOOLS
IF %T%==3 GOTO MENU
IF %T%==4 GOTO CLOSE
:LOGOFFCONFIRM1
cls
color A
shutdown /l
EXIT /B
:RESTART2
cls
color A
echo.
SET /P U=Are you sure that you want to restart your PC? Enter number 1, to do so. Enter number 2 to return to the previous sub-menu, enter number 3 to return to the main-menu or enter number 4 to exit the script. Enter:
IF %U%==1 GOTO RESTARTCONFIRM2
IF %U%==2 GOTO TOOLS
IF %U%==3 GOTO MENU
IF %U%==4 GOTO CLOSE
:RESTARTCONFIRM2
cls
color A
shutdown /r
EXIT /B
:SHUTDOWN3
cls
color A
echo.
SET /P V=Are you sure that you want to shutdown your PC? Enter number 1, to continue. Enter number 2 to return to the previous sub-menu, enter number 3 to return to the main-menu or enter number 4 to exit the script. Enter:
IF %V%==1 GOTO SHUTDOWNCONFIRM3
IF %V%==2 GOTO TOOLS
IF %V%==3 GOTO MENU
IF %V%==4 GOTO CLOSE
:SHUTDOWNCONFIRM3
cls
color A
shutdown /s
EXIT /B
:PCHEALTHGETVER
cls
color A
echo.
echo Are you sure that you want to download the newest version of pcHealth?
echo.
SET /P AC=If yes, enter the number 1, if not enter number 2 to return to the previous sub-menu. Enter:
IF %AC%==1 GOTO PCHEALTHGETVERDOWNLOADLINK
IF %AC%==2 GOTO MENU
:PCHEALTHGETVERDOWNLOADLINK
cls
color A
echo.
echo Your download will start now!
echo.
start "" https://github.com/REALSDEALS/pcHealth/archive/refs/heads/main.zip
echo.
SET /P AD=To return to the main menu enter 1, to close the script enter 2. Enter:
IF %AD%==1 GOTO MENU
IF %AD%==2 GOTO CLOSE
:HARDINFODOWN
cls
color A
echo.
echo Are you sure that you want to download the newest version of Hardware Info?
echo.
SET /P AE=If yes, enter the number 1, if not enter number 2 to return to the sub-menu. Enter:
IF %AE%==1 GOTO HARDINFODOWNLOADLINK
IF %AE%==2 GOTO PROGRAMS
:HARDINFODOWNLOADLINK
cls
color A
echo.
echo Your download will start now; if not click on 'installer' on the download page!
echo.
start "" https://www.fosshub.com/HWiNFO.html?dwl=hwi_726.exe
echo.
SET /P AF=To return to the previous sub-menu enter 1, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %AF%==1 GOTO PROGRAMS
IF %AF%==2 GOTO MENU
IF %AF%==3 GOTO CLOSE
:ADWCLEANER
cls
color A
echo.
echo Are you sure that you want to download the latest version of ADW Cleaner?
echo.
SET /P AG=If yes enter the number 1 to start the download, enter number 2 to return to the previous sub-menu. Enter:
IF %AG%==1 GOTO ADWCLEANERDOWNLOADLINK
IF %AG%==2 GOTO PROGRAMS
:ADWCLEANERDOWNLOADLINK
cls
color A
echo.
echo Your download will start now!
echo.
start "" https://downloads.malwarebytes.com/file/adwcleaner
echo.
SET /P AH=To return to the previous sub-menu enter 1, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %AH%==1 GOTO TOOLS
IF %AH%==2 GOTO MENU
IF %AH%==3 GOTO CLOSE
:DISKINFODOWN
cls
color A
echo.
echo Are you sure that you want to download the latest version of Disk Info?
echo.
SET /P AI=If yes enter the number 1 to start the download, enter the number 2 to return to the previous sub-menu. Enter:
IF %AI%==1 GOTO DISKINFODOWNLOADLINK
IF %AI%==2 GOTO PROGRAMS
:DISKINFODOWNLOADLINK
cls
color A
echo.
echo Your download will start now!
start "" https://osdn.net/projects/crystaldiskinfo/downloads/77538/CrystalDiskInfo8_17_4.zip/
echo.
SET /P AJ=To return to the previous sub-menu enter 1, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %AJ%==1 GOTO TOOLS
IF %AJ%==2 GOTO MENU
IF %AJ%==3 GOTO CLOSE
:DISKMARKDOWN
cls
color A
echo.
echo Are you sure that you want to download the latest version of Disk Mark?
echo.
SET /P AK=If yes enter the number 1 to start the download, enter the number 2 to return to the previous sub-menu. Enter:
IF %AK%==1 GOTO DISKMARKDOWNLOADLINK
IF %AK%==2 GOTO PROGRAMS
:DISKMARKDOWNLOADLINK
cls
color A
echo.
echo Your download will start now!
start "" https://osdn.net/projects/crystaldiskmark/downloads/77539/CrystalDiskMark8_0_4b.zip/
echo.
SET /P AL=To return to the previous sub-menu enter 1, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %AL%==1 GOTO TOOLS
IF %AL%==2 GOTO MENU
IF %AL%==3 GOTO CLOSE
:PRIMEDOWN
cls
color A
echo.
echo Are you sure that you want to download the latest version of Prime95? Enter:
echo.
SET /P AM=If yes enter the number 1 to start the download, enter the number 2 to return to the previous sub-menu.
IF %AM%==1 GOTO PRIMEDOWNLOADLINK
IF %AM%==2 GOTO PROGRAMS
:PRIMEDOWNLOADLINK
cls
color A
echo.
echo Your download will start now!
start "" https://www.guru3d.com/files-get/prime95-download,3.html
echo.
SET /P AN=To return to the previous sub-menu enter 1, enter number 2 to return to the main-menu or enter number 3 to exit the script. Enter:
IF %AN%==1 GOTO TOOLS
IF %AN%==2 GOTO MENU
IF %AN%==3 GOTO CLOSE
:CLOSE
EXIT /B
Main goal:
I want to make a GUI version of this script.
Problems or things that I'm struggling with:
How can I make commands like batch/ps and vbs run with each other, like for example from a click in the GUI. Because it are all languages on their own, I have now made 3 seperate folders. (The .vbs script is not my own, I got it and changed it a bit)
A local database for users to run certain test, like the battery-report and save it to a local file/database that users could later acces.
A kind of version control that when the script (GUI) is launched it would fetch from GitHub to check if there is a new version available.
I'm sorry if I'm asking some dumb questions, I'm trying to teach and help myself by doing some projects for myself. So all help is welcome! The pcHealth repo may be dumb, but a few people do use it :)
Please keep in mind that I'm not a pro, I would consider myself as a complete noob on this subject.
I'm looking forward to your responses though!
~ REALSDEALS
It is possible using python, but with a batch it is not possible.

Batch File Won't Jump to Label

I have an unfinished batch file that wont jump to the :TBS label. It will always go to the :BSO label no matter what you put in for the first question. "A" should go to :BSO and "B" should go to :TBS. I don't know how to fix this. I have tried everything I can think of. Any help appreciated.
#echo off
echo ------------------------------------------Computer Optimization and Fixer 1.1-------------------------------------------
echo.
echo Welcome to Computer Optimization and Fixer 1.1 by Anston
echo.
echo Computer Optimization and Fixer 1.1 will do a basic optimization and fix issues on your computer. For example...
echo It can run sfc, chkdsk, Defrag or Optimize, Disk Cleanup, DISM, troubleshooters, and more.
echo.
set /p A="Would you like to do a basic optimization(A) or fix a certain issue(B)?"
IF %A% EQU A GOTO:BSO
IF %A% EQU B GOTO:TBS
:BSO
echo.
echo Running basic optimization...
pause
start "dfrgui.exe" /wait "C:\Windows\System32\dfrgui.exe"
sfc /scannow
chkdsk /r
start diskclean
GOTO:END
:TBS
echo.
set /p ch="What problem do you have?(Power[A], Internet[B], Performance[C], Files[D], Windows Apps[E], Windows Update[F], Devices[G], Audio[H], Search[I], or Printer[J])
IF %ch% EQU A GOTO:PWR
IF %ch% EQU B GOTO:INT
IF %ch% EQU C GOTO:PRF
IF %ch% EQU D GOTO:FLS
IF %ch% EQU E GOTO:WNA
IF %ch% EQU F GOTO:WNU
IF %ch% EQU G GOTO:DEV
IF %ch% EQU H GOTO:AUD
IF %ch% EQU I GOTO:SCH
IF %ch% EQU J GOTO:PRN
:PWR
echo.
echo Running Troubleshooter...
msdt.exe /id PowerDiagnostic
pause
GOTO:END
:END
cls
echo ------------------------------------------Computer Optimization and Fixer 1.1-------------------------------------------
echo.
echo Thank you for using Computer Optimization and Fixer 1.1
pause
There is a command available since Windows Vista and on Windows Server versions since Windows Server 2003 for choice menus: CHOICE
#echo off
setlocal EnableExtensions DisableDelayedExpansion
set "ToolVersion=1.1"
cls
echo --------------------- Computer Optimization and Fixer %ToolVersion% ---------------------
echo/
echo Welcome to Computer Optimization and Fixer %ToolVersion% by Anston
echo/
echo Computer Optimization and Fixer %ToolVersion% will do a basic optimization
echo and fix issues on your computer. For example, it can run Check Disk
echo Utility, Disk Space Cleanup Manager for Windows, Disk System Integrity
echo Check and Repair, Disk Defragmenter, troubleshooters, and more.
echo/
echo What do you want to do?
echo/
echo A ... do a basic optimization
echo B ... fix a certain issue
echo E ... do nothing and exit
echo/
%SystemRoot%\System32\choice.exe /C ABE /N /M "Your choice:"
if errorlevel 3 goto :EOF
if errorlevel 2 goto TBS
echo/
echo Running basic optimization...
%SystemRoot%\System32\chkdsk.exe /r
%SystemRoot%\System32\cleanmgr.exe
%SystemRoot%\System32\sfc.exe /scannow
%SystemRoot%\System32\dfrgui.exe
goto END
:TBS
echo/
echo What problem do you have?
echo/
echo A ... Power
echo B ... Internet
echo C ... Performance
echo D ... Files
echo E ... Windows Apps
echo F ... Windows Update
echo G ... Devices
echo H ... Audio
echo I ... Search
echo J ... Printer
echo N ... None of above
echo/
%SystemRoot%\System32\choice.exe /C ABCDEFGHIJN /N /M "Your choice:"
echo/
goto Option%Errorlevel%
:Option1
echo Running diagnostics troubleshooting wizard ...
%SystemRoot%\System32\msdt.exe /id PowerDiagnostic
goto FINISH
:Option2
echo Check for Internet problems ...
goto FINISH
:Option3
echo Check for performance problems ...
goto FINISH
:Option4
echo Check for file problems ...
goto FINISH
:Option5
echo Check for problem with Windows Apps ...
goto FINISH
:Option6
echo Check for Windows update problems ...
goto FINISH
:Option7
echo Check for device problems ...
goto FINISH
:Option8
echo Check for audio problems ...
goto FINISH
:Option9
echo Check for search problems ...
goto FINISH
:Option10
echo Check for printer problems ...
goto FINISH
:Option11
echo Sorry, this tool cannot help you.
:FINISH
echo/
pause
:END
cls
echo --------------------- Computer Optimization and Fixer %ToolVersion% ---------------------
echo/
echo Thank you for using Computer Optimization and Fixer %ToolVersion%
echo/
endlocal
pause
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
chkdsk /?
choice /?
cleanmgr /?
cls /?
defrag /? ... console version of dfrgui.exe
dism /?
echo /?
endlocal /?
goto /?
if /?
pause /?
set /?
setlocal /?
sfc /?
Please read also:
How does the Windows Command Interpreter (CMD.EXE) parse scripts?
Where does GOTO :EOF return to?
Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files
Why is no string output with 'echo %var%' after using 'set var = text' on command line?
How to stop Windows command interpreter from quitting batch file execution on an incorrect user input?
DosTips forum topic: ECHO. FAILS to give text or blank line - Instead use ECHO/
Note: The execution of disk defragmenter is not necessary on SSD hard disks. So the batch file should check of which type each local drive is before running disk defragmenter on a drive.
PS: The names of the executables used for basic optimizations can be read by clicking with secondary (usually right) mouse button on an executable like sfc.exe, clicking in opened context menu with primary (usually left) mouse button on last menu item Properties, selecting the tab Details and looking on item File description.

How to close cmd window with command?

I make a program on cmd with 2 windows and I want to close one cmd window with a command.
if %choise%==1 goto menu
:menu
cls
color a
echo ===============================
echo MENU
echo ===============================
echo 1.Eixt 2.History
echo.
set /p choise=Choose:
if %choise%==1 exit
if %choise%==2 goto History
can anyone help?
I want to close one cmd window with a command
rem if %choise%==1 goto menu
The above line will cause an error if %choise% is not defined so remove it.
goto was unexpected at this time.
Use the following batch file:
#echo off
:menu
cls
color a
echo ===============================
echo MENU
echo ===============================
echo 1.Exit 2.History
echo.
set /p choise=Choose:
if %choise%==1 exit
if %choise%==2 goto History
endlocal
If you press 1 the batch file will exit the cmd shell
If you press 2 you will get an error as there is no label history
The system cannot find the batch label specified - History
I have two windows, "MWprog" and "History Box"
I want to close the "History box" window without closing the "MWprog" windows.
Add the following command to the batch file:
taskkill /f /fi "WINDOWTITLE eq Administrator: History Box"
Note:
The extra space - there are two after the : - is required.
To exit a batch use goto :eof [End of File]
if "%ShouldIExit%"=="TRUE" goto :EOF
or
if "%ShouldIExit%"=="TRUE" exit
or
if "%ShouldIExit%"=="TRUE" exit 2
Rem exit 2 will set the errorlevel to 2, and exit the program.
or
Search for this program on your computer, usually deep in the windows directory.
TaskKill.exe

Issue concerning path input in .bat menu

Hi I am trying to make a small menu in which the .bat file uses the user input to define a path. The code below works.
#ECHO OFF
SET /P var= Type The FULL Path In Here:
MKDIR %var%\
pause
However when I try to implement the code into the menu below. It fails and I can't read the error because it immediately exits the batch file. I am running a windows 10 machine and running the batch from the C:\ drive. The batch file makes the folders on the C:\ drive as well. I would be grateful for any help Thanks.
ECHO OFF
CLS
:MENU
ECHO.
ECHO ...............................................
ECHO PRESS 1 to select your task, or 2 TO EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Set Path
ECHO.
ECHO 2 - EXIT
ECHO.
SET /P M=Type 1 or 5 then press ENTER:
IF %M%==1 GOTO CallScript1
IF %M%==5 GOTO EOF
CallScript1
#ECHO OFF
SET /P var= Type The FULL Path In Here:
MKDIR %var%\
GOTO:EOF
You are missing the colon before the label CallScript1 on line 17
i.e. replace
CallScript1
with
:CallScript1

Menus in Batch File

I don't usually create batch files as I just type what I need into the run box or the command prompt but I'm trying to make one just to let me access basic utilities in windows and check up on things (I really don't need it but I think my dad would find it helpful). I am familiar (but new) with python so if using python for these things is a better option I can do that, however I thought batch was the best way of doing something as simple as this. The problem is with my menu. I think because of my menu , it is cycling through all of the commands before doing the command selected. Any help with this will be fully appreciated, the batch script is in a code box below.
echo off
:menu
echo This is a simple cleanup and repair utility. Please select an option:
echo 1 - Check the hard disk c:\ for errors and inconsistancies.
echo 2 - Renew the IP address
echo 3 - View IP Address information
echo 4 - Check internet connection by pinging http://www.google.co.uk/
echo 5 - Start disk cleanup utility
echo 6 - ping 192.168.0.1
echo 7 - ping 192.168.1.1
echo 8 - Open notepad
choice /n /c:12345678 /M "Choose an option (1-8) "
IF ERRORLEVEL == 1 GOTO CHKDSK
IF ERRORLEVEL == 2 GOTO RENEW
IF ERRORLEVEL == 3 GOTO DISPLAYIP
IF ERRORLEVEL == 4 GOTO PINGGOOGLE
IF ERRORLEVEL == 5 GOTO CLEANMGR
IF ERRORLEVEL == 6 GOTO PING0
IF ERRORLEVEL == 7 GOTO PING1
IF ERRORLEVEL == 8 GOTO STARTNOTE
:CHKDSK
CHKDSK C:
PAUSE
goto menu
:RENEW
IPCONFIG /RENEW
PAUSE
goto menu
:DISPLAYIP
IPCONFIG /ALL
PAUSE
goto menu
:PINGGOOGLE
PING HTTP://WWW.GOOGLE.CO.UK/
PAUSE
goto menu
:CLEANMGR
CLEANMGR
PAUSE
goto menu
:PING0
PING 192.168.0.1
PAUSE
goto menu
:PING1
PING 192.168.1.1
PAUSE
goto menu
:STARTNOTE
START NOTEPAD
PAUSE
goto menu
You may use a much simpler approach if you don't test the errorlevel value at all, but just use it to assemble a goto command with multiple destinations. In order for this method to work, the labels must be changed so they include the errorlevel values.
echo off
:menu
echo This is a simple cleanup and repair utility. Please select an option:
echo 1 - Check the hard disk c:\ for errors and inconsistancies.
echo 2 - Renew the IP address
echo 3 - View IP Address information
echo 4 - Check internet connection by pinging http://www.google.co.uk/
echo 5 - Start disk cleanup utility
echo 6 - ping 192.168.0.1
echo 7 - ping 192.168.1.1
echo 8 - Open notepad
choice /n /c:12345678 /M "Choose an option (1-8) "
GOTO LABEL-%ERRORLEVEL%
:LABEL-1 CHKDSK
CHKDSK C:
PAUSE
goto menu
:LABEL-2 RENEW
IPCONFIG /RENEW
PAUSE
goto menu
:LABEL-3 DISPLAYIP
IPCONFIG /ALL
PAUSE
goto menu
:LABEL-4 PINGGOOGLE
PING HTTP://WWW.GOOGLE.CO.UK/
PAUSE
goto menu
:LABEL-5 CLEANMGR
CLEANMGR
PAUSE
goto menu
:LABEL-6 PING0
PING 192.168.0.1
PAUSE
goto menu
:LABEL-7 PING1
PING 192.168.1.1
PAUSE
goto menu
:LABEL-8 STARTNOTE
START NOTEPAD
PAUSE
goto menu
The errorlevel is a bit funny. When you compare like that, it actually checks if the number is equal OR greater than. So to make it work your current way, you need to order the tests in reverse (starting with higher errorlevels, and working down to errorlevel 0, always using a GOTO jump for each condition).
The other way to do it is use the environment variable:
if "%errorlevel%"=="4" goto :PINGGOOGLE
It's usually a good idea to put goto :menu after all the tests, just in case none of the tests pass. For example, if the user presses Ctrl-C, the errorlevel comes out as zero. In your code (after you fix the tests), it will fall through to the :CHKDSK section.
Change the ErrorLevel part to
IF %ERRORLEVEL%==1 GOTO CHKDSK
IF %ERRORLEVEL%==2 GOTO RENEW
IF %ERRORLEVEL%==3 GOTO DISPLAYIP
IF %ERRORLEVEL%==4 GOTO PINGGOOGLE
IF %ERRORLEVEL%==5 GOTO CLEANMGR
IF %ERRORLEVEL%==6 GOTO PING0
IF %ERRORLEVEL%==7 GOTO PING1
IF %ERRORLEVEL%==8 GOTO STARTNOTE
goto menu
Note that the if command comparisons are space sensitive therefore, "0 "==" 0" will not be equal.

Resources