Is my batch file compatible with all computers? - batch-file

Will this work on Windows 8 and always work? I've tested it on Windows 7 but I'm not sure... I had a friend test it and he said that it coudn't find the correct path but I checked and the syntax of the commands is the same and I don't know why there'd be a problem. This is assuming %USERPROFILE%\Documents\My Games\Terraria\Players and %USERPROFILE%\Google Drive exists already
#echo off
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
) else (
echo Failure: Current permissions inadequate. Please run as administatior.
pause >nul
exit
)
echo ---------------------------------------------
echo Below enter "S" for simple install type or "A" for avanced install type.
echo (Simple is recommended, only use advanced if you know what your doing!)
echo ---------------------------------------------
set /p option=Enter:
if /i "%option%"=="S" goto simple
if /i "%option%"=="A" goto advanced
echo Your entry did not match available options. Try again.
pause >nul
exit
:simple
mklink /d "%USERPROFILE%\Google Drive\Terraria" "%USERPROFILE%\Documents\My Games\Terraria\Players"
cd %USERPROFILE%\Google Drive\Terraria\
copy /y NUL marker >nul
cd %USERPROFILE%\Documents\My Games\Terraria\Players
if exist marker (
echo Validation of installation complete. Symbolic link functional.
del marker
) else (
echo SOMETHING WENT WRONG!!!!!!!!
)
echo ==============
echo You Selected Simple. & echo.If there are no errors above, your installation should be complete.
echo ==============
pause >nul
exit
:advanced
mkdir "%USERPROFILE%\Google Drive\Terraria"
mklink /d "%USERPROFILE%\Google Drive\Terraria\Players" "%USERPROFILE%\Documents\My Games\Terraria\Players"
cd %USERPROFILE%\Google Drive\Terraria\Players
copy /y NUL marker >nul
cd %USERPROFILE%\Documents\My Games\Terraria\Players
if exist marker (
echo Validation of installation complete. Symbolic link functional.
del marker >nul
) else (
echo SOMETHING WENT WRONG!!!!!!!!
)
echo ==============
echo You Selected Advanced. & echo.If there are no errors above, your installation should be complete.
echo ==============
pause >nul
exit

If delivered that all paths exist....
mklink command was introduced in Vista so the script won't work on XP/2003.

Related

trying to get administrative permission(without uac) in batch file

#echo off
goto check_Permissions
:check_Permissions
SET "C:\Users\BDAS\Desktop\check_admin=%~dp0"&SET "check_admin=%~dpf0"
net session >nul 2>nul & if errorlevel 1 check_admin "%~0" %*
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed. > res_txt.txt
) else (
echo Failure: Current permissions inadequate. > res_txt.txt
)
pause
Detecting elevation can be done more simply with openfiles:
openfiles > NUL 2>&1 && (
echo Administrative permissions confirmed.
exit /b 0
) else (
echo Current permissions inadequate.
exit /b 1
)
The full script to run notepad.exe with administrative privileges is here:
#echo off
setlocal enableextensions enabledelayedexpansion
REM Check admin mode, auto-elevate if required.
openfiles > NUL 2>&1 || (
REM Not elevated. Do it.
echo createObject^("Shell.Application"^).shellExecute "%~dpnx0", "%*", "", "runas">"%TEMP%\%~n0.vbs"
cscript /nologo "%TEMP%\%~n0.vbs"
goto :eof
)
del /s /q "%TEMP%\%~n0.vbs" > NUL 2>&1
)
REM If here, then process is elevated. Otherwise, batch is already terminated and/or stuck in code above.
start "" notepad.exe
goto :eof
In no way you can bypass UAC, but by disabling it fully for the current account. If it was possible to do so, absolutely NO Windows machine connected to Internet would be virus-free since YEARS. But at least, the batch will handle automatically the elevation request, so if you forget to run it as Administrator, it will prompt you to allow elevation.

Send files to a ftp server and then check if it was really sent using .bat

I was making a .bat code to send .txt files to a specific folder on my ftp server. But I also wanted a way to check if these files were really uploaded. I searched a lot on the internet and unfortunately, I realized that it can't be done using .bat command.
So I tried using another way: The .bat will send the files and then will take it back to the folder, if the file already exists in the folder it will show a message that the file was successfully uploaded.
I did this script below, but the part of the "checking if was uploaded" is not working right.
Someone can help me?
#echo off
#setlocal enableextensions
#cd /d "%~dp0"
mode 34,12
color 0a
Ping www.google.nl -n 1 -w 1000 >nul 2>nul
if errorlevel 1 (set internet=Nao foi possivel se conectar ao servidor) else (set internet=Conectado) >nul 2>nul
echo %internet%
if "%internet%"=="No connection" goto 1
if "%internet%"=="Conected" goto 2
:1
echo No connection
echo.
echo Try later...
echo.
pause
exit
:2
( echo open ftp.xxxxxxxxxxx.com
echo xxxxxxx
echo xxxxxxx
echo ascii
echo lcd "c:\Vendas Pay&Go\files"
echo cd "Vendas Cartões Pay&Go"
echo cd "ECO"
echo mput *.txt
echo bye
)> %temp%\ftpsend.dat
ftp -i -s:%temp%/ftpsend.dat >nul 2>nul
del /f /s /q %temp%\ftpsend.dat >nul 2>nul
( echo open ftp.xxxxxxx.com
echo xxxxxxx
echo xxxxxxx
echo ascii
echo lcd "c:\Vendas Pay&Go\files"
echo cd "Vendas Cartões Pay&Go"
echo cd "ECO"
echo mget *.txt
echo bye
)> %temp%\ftpsend.dat
ftp -i -s:%temp%/ftpsend2.dat >nul 2>nul
del /f /s /q %temp%\ftpsend2.dat >nul 2>nul
if %*.txt% exist goto3
:4
echo File was not uploaded
pause
:3
echo File Uploaded.
del /s /f /q "c:\Vendas Pay&Go\files\*.txt"
If you want to conditional execution to display a message you can do something like this. The && means the previous command was successful. The || means the previous command was not successful.
(ftp -i -s:%temp%/ftpsend.dat | find /I "file successfully transferred" >nul) && (echo File Successfully Transferred) || ( echo File not transferred. Tray again later.)
Updated version based on comment below
(ftp -i -s:%temp%/ftpsend.dat | find /I "file successfully transferred" >nul) && (
echo File successfully sent.
del /f /s /q "c:\Vendas Pay&Go\files\*.txt" >nul
) || (
cls
echo File not uploaded. Try later.
)

Update Currently Running Batch Script

Playing around with my Batch script again. It was brought to my attention that my update routine was not working correctly. Iteration 1 would result in the running script being deleted and not copying the new version from a folder I had selected. Iteration 2 now deletes the old script and copies the new script but with each line of code I change I end up with the currently running script closing, and the new updated script not launching.
Here's a snippet of the Update routine:
:Options
REM I'll set the variable here to what is set elsewhere in the script.
SET VERSION=Version 1.7
CLS
ECHO.
ECHO.
ECHO %VERSION%
ECHO.
ECHO.
ECHO ==================== OPTIONS =====================
ECHO.
ECHO 1. Update Script WIP
ECHO 2. Install entire script to Statup Folder
ECHO 3. Install individual items for auto-launch
ECHO 4. Install Windows Logout feature
ECHO 5. Uninstall
ECHO 6. Change Colors
ECHO 7. Changelog
ECHO.
ECHO =======PRESS 'Q' TO QUIT OR 'B' TO GO BACK========
ECHO.
SET OPTION=
SET /P OPTION=Select an Option:
IF /I '%OPTION%'=='1' GOTO Update
IF /I '%OPTION%'=='2' GOTO Install
IF /I '%OPTION%'=='3' GOTO I_Install
IF /I '%OPTION%'=='4' GOTO I_Logout
IF /I '%OPTION%'=='5' GOTO Uinstall
IF /I '%OPTION%'=='6' GOTO Colors
IF /I '%OPTION%'=='7' GOTO Changelog
IF /I '%OPTION%'=='q' GOTO quit
IF /I '%OPTION%'=='quit' GOTO quit
IF /I '%OPTION%'=='b' GOTO menu
IF /I '%OPTION%'=='back' GOTO menu
ECHO.
ECHO ============INVALID INPUT============
ECHO Please select a number
ECHO or select 'Q' or 'B'.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO Options
:Update
ECHO.
IF EXIST "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" (
GOTO Update_1
) ELSE (
ECHO You have not installed the script yet. Please install the script first.
)
PAUSE
GOTO Options
:Update_1
IF EXIST "%userprofile%\AppData\Local\Temp\Update.bat" (
GOTO Update_2
) ELSE (
REM Here the main script writes an update script to a batch file
ECHO DEL "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" > "%userprofile%\AppData\Local\Temp\Update.bat"
REM I replaced the original file location with one on the desktop. The original location was on a network drive, location is confidential.
ECHO COPY "%userprofile\Desktop\Shortcut Browser *.bat" "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup" >> "%userprofile%\AppData\Local\Temp\Update.bat"
ECHO CALL "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" >> "%userprofile%\AppData\Local\Temp\Update.bat"
ECHO EXIT >> "%userprofile%\AppData\Local\Temp\Update.bat"
)
GOTO Update_2
REM Here the main script calls upon the update script
:Update_2
CALL "%userprofile%\AppData\Local\Temp\Update.bat"
REM The script seems to hang here. Either both the scripts will remain open or close or a combination depending on where CALL and START were used.
PAUSE
GOTO Options
I saw elsewhere I could have used the FC command. I didn't know about it until troubleshooting this problem. I've gotten this far and I feel I'm just missing some small trick to get the new updated script to launch.
If you need any more info let me know. I think I covered everything.
#ECHO OFF
SETLOCAL
TITLE Super Script 5000
:Options
REM I'll set the variable here to what is set elsewhere in the script.
SET VERSION=Version 1.7
CLS
ECHO.
ECHO.
ECHO %VERSION%
ECHO.
ECHO.
ECHO ==================== OPTIONS =====================
ECHO.
ECHO 1. Update Script WIP
ECHO 2. Install entire script to Statup Folder
ECHO 3. Install individual items for auto-launch
ECHO 4. Install Windows Logout feature
ECHO 5. Uninstall
ECHO 6. Change Colors
ECHO 7. Changelog
ECHO.
ECHO =======PRESS 'Q' TO QUIT OR 'B' TO GO BACK========
ECHO.
SET "OPTION="
SET /P "OPTION=Select an Option: "
IF /I "%OPTION%"=="1" GOTO Update
IF /I "%OPTION%"=="2" GOTO Install
IF /I "%OPTION%"=="3" GOTO I_Install
IF /I "%OPTION%"=="4" GOTO I_Logout
IF /I "%OPTION%"=="5" GOTO Uinstall
IF /I "%OPTION%"=="6" GOTO Colors
IF /I "%OPTION%"=="7" GOTO Changelog
IF /I "%OPTION%"=="q" GOTO quit
IF /I "%OPTION%"=="quit" GOTO quit
IF /I "%OPTION%"=="b" GOTO menu
IF /I "%OPTION%"=="back" GOTO menu
ECHO.
ECHO ============INVALID INPUT============
ECHO Please select a number
ECHO or select 'Q' or 'B'.
ECHO ======PRESS ANY KEY TO CONTINUE======
PAUSE > NUL
GOTO Options
:Update
ECHO.
IF EXIST "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat" (
GOTO Update_1
) ELSE (
ECHO You have not installed the script yet. Please install the script first.
)
PAUSE
GOTO Options
:Update_1
IF EXIST "%tmp%\update.bat" (
2>NUL DEL "%tmp%\update.bat" || GOTO Options
)
SETLOCAL
FOR %%A IN (
"%appdata%\Microsoft\Windows\Start Menu\Programs\Startup\Shortcut Browser *.bat"
) DO (
SET "old_version=%%~A"
SET "old_dir=%%~dpA"
SET "old_file=%%~nxA"
)
FOR %%A IN (
"%userprofile%\Desktop\Shortcut Browser *.bat"
) DO (
SET "new_version=%%~A"
SET "new_dir=%%~dpA"
SET "new_file=%%~nxA"
)
IF NOT DEFINED old_version (
ENDLOCAL
GOTO Options
) ELSE IF NOT DEFINED new_version (
ENDLOCAL
GOTO Options
)
(
ECHO #ECHO OFF
ECHO SETLOCAL
ECHO.
ECHO ECHO Update and restarting...
ECHO ^>NUL PING localhost -n 3
ECHO.
ECHO SET "old_version=%old_version%"
ECHO SET "new_version=%new_version%"
ECHO SET "updated_version=%old_dir%\%new_file%"
ECHO.
ECHO CALL :log /clear_log
ECHO.
ECHO IF NOT EXIST "%%new_version%%" (
ECHO CALL :log ERROR: Not exist "%%new_version%%".
ECHO EXIT /B 1
ECHO ^)
ECHO.
ECHO CALL :log Move old_version to old_version.bak.
ECHO MOVE "%%old_version%%" "%%old_version%%.bak" ^|^| (
ECHO CALL :log ERROR: Move failed to backup old version.
ECHO EXIT /B 2
ECHO ^)
ECHO.
ECHO CALL :log Copy new_version to old_version.
ECHO COPY "%%new_version%%" "%%appdata%%\Microsoft\Windows\Start Menu\Programs\Startup\" ^|^| (
ECHO CALL :log ERROR: Copy failed. Restore old version.
ECHO MOVE "%%old_version%%.bak" "%%old_version%%" ^|^| (
ECHO CALL :log ERROR: Restore old version failed.
ECHO EXIT /B 3
ECHO ^)
ECHO EXIT /B 4
ECHO ^)
ECHO.
ECHO CALL :log Delete old_version.bak.
ECHO DEL "%%old_version%%.bak" ^|^| (
ECHO CALL :log WARNING: Delete backup file failed.
ECHO ^)
ECHO.
ECHO IF NOT EXIST "%%updated_version%%" (
ECHO CALL :log ERROR: Not exist: "%%updated_version%%"
ECHO EXIT /B 5
ECHO ^)
ECHO.
ECHO ENDLOCAL
ECHO.
ECHO ECHO Ready to restart updated version
ECHO PAUSE
ECHO CALL "%old_dir%\%new_file%"
ECHO EXIT /B
ECHO.
ECHO :log
ECHO SETLOCAL
ECHO SET "log=%%tmp%%\update.log"
ECHO IF /I "%%~1"=="/clear_log" TYPE NUL ^> "%%log%%" ^& EXIT /B
ECHO IF /I "%%~1"=="/delete_log" 2^>NUL DEL "%%log%%" ^& EXIT /B
ECHO SET args=%%*
ECHO IF NOT DEFINED args EXIT /B
ECHO ECHO %%*
ECHO ^>^> "%%log%%" ECHO %%*
ECHO EXIT /B
) > "%tmp%\update.bat"
ENDLOCAL
START "Super Script 5000" "cmd /c "%tmp%\update.bat""
EXIT
:Quit
Tested on a Win7 VM. The script needs to restart on update else
weird issues may occur. CMD does not like scripts changing as it
is reading and interpreting them. Even reusing the same console
using START with /B may cause key input issues.
update.bat is overwritten every update as it stores absolute paths
so each update will be different paths with the filenames changing.
Using a wildcard with CALL may not work too well otherwise.
update.bat moves the old version to a .bak file, copies the new
version and if successful, deletes the .bak file, else moves the
.bak file to the old version. This is just to ensure a current
version always exists even if the update fails.
Changed quotes in :Options label from ' to ". Quotes are not
interchangeable like some other languages. Example: "%OPTION%"
will work if contains a space though '%OPTION%' may cause error.
I notice no SETLOCAL at the top of your full script. Advise you add
it unless you have a good reason not to.
I merged labels :Update_1 and :Update_2 into one.
Perhaps adjust Ping localhost -n number if more or less time is
needed.
Look at the %tmp%\update.log if a problem happens. Though expect
the errors to show in the console as the label :log in
update.bat echoes to console and writes to the log.

Batch file over network path

I have the following batch script to make life easier at work.
Here is what it is supposed to work:
1- Drag and drop some file onto the .bat
2- Choose file's destination on the "menu"
3- Script copy's files to destination folder
4- Script executes remote procedure (that's the PSexec line)
5- Script copy's the result of the remote procedure to other folders.
And this works fine... except for a "small" detail with which i need some help.
When i try to copy the network location \10.250.39.116\d%... if i haven't previously logged into that machine it wont work.
I've been looking into the 'net use' command to overcome this, but i'm not sure if it suits my needs.
There are a total of 4 different machines i need to authenticate, dependent on the choice of the menu.
Actual Question:
Can i log in to such machines with the batch, and avoid creating duplicate connections every time i run the script ? If so, how?
Thank you for your time!
:)
I know the paths I have all point to the same place :)
#echo off
setlocal enabledelayedexpansion
ECHO.
ECHO ...............................................
ECHO PRESS 1, 2 OR 3 to select your task, or 4 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Compilar em Qualidade
ECHO 2 - Compilar na HSDEV
ECHO 3 - Compilar nas DEMOS
ECHO 4 - EXIT
ECHO.
SET /P M=Type 1, 2, 3, or 4 then press ENTER:
IF %M%==1 GOTO :QUAL
IF %M%==2 GOTO :HSDEV
IF %M%==3 GOTO :DEMO
IF %M%==4 GOTO EOF
:QUAL
set "PathForms6=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\compilador\fmb6i\GH\"
set "PathForms10=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\compilador\fmb10\GH\"
set PathCompilador=\\10.250.39.116 -u Administrator -p Password1 cmd "/C d: & cd d:\GLINTTHSIAS\GLINTTHS\compilador & GH_PRIV_10_02_Forms.bat"
set PathDestinoPriv=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\PRIV\GH
set PathDestinoPub=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\PUB\GH
goto :PROCESSA
goto EOF
:HSDEV
set "PathForms6=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\compilador\fmb6i\GH\"
set "PathForms10=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\compilador\fmb10\GH\"
set PathCompilador=\\10.250.39.116 -u Administrator -p Password1 cmd "/C d: & cd d:\GLINTTHSIAS\GLINTTHS\compilador & GH_PRIV_10_02_Forms.bat"
set PathDestinoPriv=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\PRIV\GH
set PathDestinoPub=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\PUB\GH
goto :PROCESSA
goto EOF
:DEMO
set "PathForms6=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\compilador\fmb6i\GH\"
set "PathForms10=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\compilador\fmb10\GH\"
set PathCompilador=\\10.250.39.116 -u Administrator -p Password1 cmd "/C d: & cd d:\GLINTTHSIAS\GLINTTHS\compilador & GH_PRIV_10_02_Forms.bat"
set PathDestinoPriv=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\PRIV\GH
set PathDestinoPub=\\10.250.39.116\d$\GLINTTHSIAS\GLINTTHS\PUB\GH
goto :PROCESSA
goto EOF
:PROCESSA
set argCount=0
for %%x in (%*) do (
set /A argCount+=1
set "argVec[!argCount!]=%%~nx"
set "pathVec[!argCount!]=%%~dpx"
)
rem echo Number of processed arguments: %argCount%
for /L %%i in (1,1,%argCount%) do (
echo Vou compilar %%i - "!argVec[%%i]!"
if exist %PathForms6%!argVec[%%i]!.* del /q %PathForms6%!argVec[%%i]!.*
if exist %PathForms10%!argVec[%%i]!.* del /q %PathForms10%!argVec[%%i]!.*
robocopy "!pathVec[%%i]!." %PathForms6% !argVec[%%i]!.fmb > nul
)
c:
cd c:\pstools
psexec %PathCompilador%
for /L %%i in (1,1,%argCount%) do (
if exist "%PathForms10%!argVec[%%i]!.fmx" (
xcopy %PathForms10%!argVec[%%i]!.fmx %PathDestinoPriv% /y
xcopy %PathForms10%!argVec[%%i]!.fmx %PathDestinoPub% /y)
)
pause
How much testing have you done with net use? Try running it twice at the command line. Notice how the output changes at the second running:
As you can see, where a connection has already been established, net use will output a summary of the connection rather than creating a duplicate connection.
If you prefer, you could use conditional execution or errorlevel checking. Using this method, you can avoid calling net use until xcopy fails, which should only be the first time. Here's a short example, simply to illustrate the mechanics:
#echo off
setlocal
ping -n 1 10.250.39.116 | find /i "TTL=" >NUL || (
echo 10.250.39.116 is offline. Unable to continue. Press any key to exit.
pause >NUL
goto :EOF
)
call :xcopy "%~1" "destination"
echo Press any key to exit.
pause >NUL
net use \\10.250.39.116\d$ /delete >NUL 2>NUL
goto :EOF
:xcopy <source> <dest_dir>
xcopy /L "%~1" "%~2" 2>NUL || (
net use \\10.250.39.116\d$ /user:username password >NUL 2>NUL
xcopy /L "%~1" "%~2"
)
goto :EOF

Need some input on a batch file im working on

#echo off
:options
cls
echo Please select an operation:
echo.
echo 1. Mount TrueCrypt Volume
echo 2. Start TrueCrypt
echo 3. Dismount All TrueCrypt Volumes
echo 4. Exit
set /p option=" Option: "
:files
cls
echo Please choose a file:
echo.
echo 1. Tor
echo 2. Other_files
echo 3. Main Menu
set /p file=" File: "
if %option%==1 (
goto files
)
if %option%==2 (
TrueCrypt\TrueCrypt.exe
echo Operation Complete.
pause
goto options
)
if %option%==3 (
TrueCrypt\TrueCrypt.exe /q /d
echo Operation Complete.
pause
goto options
)
if %option%==4 (
exit
)
else(
echo Invalid Input.
echo Please try again . . .
pause > nul
goto options
)
if %file%==1 (
TrueCrypt\TrueCrypt.exe /q background /e /m rm /v "Tor"
echo Operation Complete.
pause
goto files
)
if %file%==2 (
TrueCrypt\TrueCrypt.exe /q background /e /m rm /v "Other_files"
echo Operation Complete.
pause
goto files
)
if %file%==3(
goto options
)
else(
echo Invalid Input.
echo Please try again . . .
pause > nul
goto files
)
This is a batch file I typed up to call hidden and encrypted volumes made with TrueCrypt.
Now the Options "screen" works fine, each option does as it is suppose to. But the Files "screen" doesn't do anything it is suppose to, you select a file you want to open and it does nothing just sits there, it doesn't give an error or anything so that's where it stumps me.
I am relatively a noob when it comes to Batch but I do have other programming knowledge.
But I was hoping someone would be able to help!
You've got some problems with spacing, notably the if %file%==3( line. There needs to be a space between the 3 and the (. Without that space, you'll get The syntax of the command is incorrect. The batch language doesn't lend itself to code golfing, and spacing or not spacing is important.
There's a glaring logic issue, in that you're going to visit :files whether a relevant %option% has been input or not.
There are also a couple of general batch scripting conventions that may help you in the long run if you get them under your fingers now. Whenever you set a variable to a string, consider placing the set "var=value" pair in quotation marks. Also, quote each side of the comparison operator in your if statements. Such changes won't affect this script, but the habits will result in less troubleshooting in the future.
Anyway, here's your script, fixed:
#echo off
:options
cls
set option=
echo Please select an operation:
echo.
echo 1. Mount TrueCrypt Volume
echo 2. Start TrueCrypt
echo 3. Dismount All TrueCrypt Volumes
echo 4. Exit
set /p "option=Option: "
if "%option%"=="1" (
goto files
) else if "%option%"=="2" (
TrueCrypt\TrueCrypt.exe
echo Operation Complete.
pause
goto options
) else if "%option%"=="3" (
TrueCrypt\TrueCrypt.exe /q /d
echo Operation Complete.
pause
goto options
) else if "%option%"=="4" (
exit /b
) else (
echo Invalid Input.
echo Please try again . . .
pause > nul
goto options
)
:files
cls
set file=
echo Please choose a file:
echo.
echo 1. Tor
echo 2. Other_files
echo 3. Main Menu
set /p "file=File: "
if "%file%"=="1" (
TrueCrypt\TrueCrypt.exe /q background /e /m rm /v "Tor"
echo Operation Complete.
pause
goto files
) else if "%file%"=="2" (
TrueCrypt\TrueCrypt.exe /q background /e /m rm /v "Other_files"
echo Operation Complete.
pause
goto files
) else if "%file%"=="3" (
goto options
) else (
echo Invalid Input.
echo Please try again . . .
pause > nul
goto files
)
You have an infinite loop here:
:files
cls
echo Please choose a file:
echo.
echo 1. Tor
echo 2. Other_files
echo 3. Main Menu
set /p file=" File: "
if %option%==1 (
goto files
)
So if the user enters Option 1, then the IF condition will send them to the files menu which is above. The user enters, for example File 2, but %option% is still 1. The IF statement statement then sends them back to files...
To fix this you should set another label (for example, filesExecute) and have the IF statement send the control there:
if %option%==1 (
goto filesExecute
)
Now define your filesExecute label in the appropriate spot:
...
REM Add new label here.
:filesExecute
if %file%==1 (
TrueCrypt\TrueCrypt.exe /q background /e /m rm /v "Tor"
echo Operation Complete.
pause
goto files
)
if %file%==2 (
...

Resources