Want to make a installer for a game i play:
#echo off
echo.
echo Choose One
echo __________
echo.
echo 32
echo.
echo 64
echo.
echo Idk
echo.
echo __________
echo.
echo.
set/p bit=
goto %bit%
:32
xcopy "warcraft3" C:\Program Files
pause
goto done
:64
xcopy "warcraft3" C:\Program Files(x86)
pause
goto done
:idk
xcopy "warcraft3" C:\Program Files
pause
goto done
:done
the "warcraft3" is a folder not a zip or anything, it says it cant find the specified file.
Need quotes around folders with spaces
xcopy "warcraft3" "C:\Program Files\"
also good practice to put a trailing slash on destination folders.
Related
I'm trying to zip up 27 exe files in one go using a batch file. The purpose of this file is to create .7z files for a modified HBCD menu. This file is located in, ...\Documents\CD\HBCD\Programs the exe files are in ...\Documents\CD\HBCD\Programs\Files\SysinternalsSuite
I keep getting:
Error:
Incorrect command line
I keep searching around and trying different things but I can't get it to work.
File Name: 7zBatch.bat
#echo off
SETLOCAL ENABLEDELAYEDEXPANSION
pushd "%~dp0"
echo "-------------------------------------------------"
echo "||======== BATCH ZIPPER (.7z) for HBCD ========||"
echo "-------------------------------------------------"
:AskSource
echo Enter the location of the exe file(s)
set SOURCE=
set /p SOURCE=">>" %=%
echo "%SOURCE%", is that correct & goto ConfirmSource
:ConfirmSource
echo (Y)es or (N)o?
set INPUT=
set /p INPUT=">>" %=%
if /I "%INPUT%"=="y" goto AskDest
if /I "%INPUT%"=="n" goto AskSource
echo Incorrect input, is the location correct? & goto ConfirmSource
:AskDest
cd %SOURCE%
echo Enter the location of the zip file(s)
set DEST=
set /p DEST=">>" %=%
echo "%DEST%", is that correct & goto ConfirmDest
:ConfirmDest
echo (Y)es or (N)o?
set INPUT=
set /p INPUT=">>" %=%
if /I "%INPUT%"=="y" goto Execute
if /I "%INPUT%"=="n" goto AskDest
echo Incorrect input, is the location correct? & goto ConfirmDest
:Execute
FOR /f "tokens=*" %%G IN ('dir /b *.exe') DO (
set fname=%%G
set nfname=!fname:.exe=!
echo.
echo Found: !fname!
..\..\7z.exe a -t7z !nfname!.7z "!fname!" -mx5 -sdel -oC:%DEST%
timeout /t 10 /nobreak
)
ENDLOCAL
echo.
pause
Once it gets to the 7 Zip line it gives the error. I realized that the nfname variable was empty so I tried:
set nfname=!%%G:.exe=!
That didn't work so I tried deleting that and going with:
..\..\7z.exe a -t7z !fname:.exe=!.7z "!fname!" -mx5 -sdel -oC:%DEST%
That didn't work so I tried putting different things in quotes one by one and then everything:
"..\..\7z.exe" a -t7z "!fname:.exe=!.7z" "!fname!" -mx5 -sdel -oC:"%DEST%"
Still nothing. What am I missing?
#echo off
SETLOCAL
echo "-------------------------------------------------"
echo "||======== BATCH ZIPPER (.7z) for HBCD ========||"
echo "-------------------------------------------------"
:AskSource
echo Enter the location of the exe file(s)
set "SOURCE="
set /p "SOURCE=>>"
echo "%SOURCE%", is that correct
:ConfirmSource
echo (Y)es or (N)o?
set "INPUT="
set /p "INPUT=>>"
if /I "%INPUT%"=="y" goto AskDest
if /I "%INPUT%"=="n" goto AskSource
echo Incorrect input, is the location correct?
goto ConfirmSource
:AskDest
echo Enter the location of the zip file(s)
set "DEST="
set /p "DEST=>>"
echo "%DEST%", is that correct
:ConfirmDest
echo (Y)es or (N)o?
set "INPUT="
set /p "INPUT=>>"
if /I "%INPUT%"=="y" goto Execute
if /I "%INPUT%"=="n" goto AskDest
echo Incorrect input, is the location correct?
goto ConfirmDest
:Execute
FOR %%G IN ("%SOURCE%\*.exe") DO (
"%~dp0..\..\7z.exe" a -t7z "%DEST%\%%~nG.7z" "%%~fG" -mx5 -sdel
)
ENDLOCAL
echo.
pause
The pushd and cd removed. Unsure why 7z.exe would be
located 2 directories up from where the input executable
directory is located. 7z.exe is now located 2 directories
up from the script directory.
The -o switch for 7z.exe is only for extraction as
mentioned in the help file so is omitted.
Double quoted set of variables to avoid any trailing spaces.
The for loop changed to simple type as it gives the file
paths required without need of using dir.
EnableDelayedExpansion removed as the for variables
uses modifiers to get fullpath, name, drive etc. See
for /? about modifiers available.
Removed timeout as it complains if stdin is used and see
no reason to use it for this task.
Removed obsolete goto commands that go to the next line
with a command.
I have this script to send files to my ftp:
#echo off
#setlocal enableextensions
#cd /d "%~dp0"
color 0a
mode 34,12
title Enviar Vendas Eco
echo.
echo.
echo.
echo.
echo Sending ...
echo.
echo.
echo Wait ...
( echo open ftp.xxxxxxxxxxxxx.com
echo xxxxxxx
echo xxxxxx
echo ascii
echo prompt
echo cd "place1"
echo cd "place2"
echo lcd "%userprofile%\Desktop\test"
echo mput *.txt -overwrite
echo bye
)> %temp%\ftpsend.dat
ftp -s:%temp%/ftpsend.dat >nul 2>nul
del /f /s /q %temp%\ftpsend.dat >nul 2>nul
exit
By default, the script would must overwrite the files if already exists on .ftp. But it isn't happening.
What is wrong on my script?
When i run appears the file was suceffully transfered, but it didn't replace the file that already exists on ftp.
Look the image:
Ive been looking for answer to this question but so far unsucessfully. Can i somehow make it that after batch file is started it wouldnt close if you would press X button on top right (the exit button)? If yes, how to do that?
code for "fake virus"
#echo off
color 47
net stop themes >nul
title DEEP VIRAL INFECTION!
echo VIRAL INFECTION!!!
echo VIRAL INFECTION!!!
echo VIRAL INFECTION!!!
echo ERROR!!!
echo -
echo virus - TROJAN_DEMOLISHER code #45643676
echo -
echo FIREWALL - FAILED
echo -
echo ANTI-VIRUS - FAILED
echo -
echo IP ADDRESS BREACHED!
echo -
echo VIRUS ATTAINING: ****-****-****-8894
echo -
pause
cls
echo -
echo SCANNING INFECTED AREAS...
echo -
pause
title SCANNING INFECTED AREAS...
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
:end
cls
title DEEP VIRAL INFECTION!
echo -
echo 86.5 PERCENT OF MEMORY INFECTED
echo -
echo INFECTION FATAL!
echo -
echo DELETION OF ENTIRE CONTENTS OF LOCAL DISK C: REQUIRED
echo -
pause
cls
echo -
title DELETING HARD-DRIVE C:
echo -
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
cls
title DEEP VIRAL INFECTION!
echo -
echo CONTENTS OF HARD-DRIVE C: ERASED
echo -
pause
cls
echo -
echo SCANNING...
echo -
title SCANNING...
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
dir /s "C:\program files\"
:end1
cls
title DEEP VIRAL INFECTION!
echo -
echo 0.00 PERCENT OF HARD-DRIVE INFECTED
echo -
pause
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
echo ERROR
pause
cls
title SYSTEM FAILURE
color 17
echo ERROR!
echo -
echo VISUAL MEMORY LOST!
echo -
echo RAM LOST!
echo -
echo CORE PROCESSOR FAILING...
echo -
echo TOTAL SYSTEM CRASH IMMINENT!
echo -
echo -
pause
cls
echo -
echo -
echo -
echo SHUTDOWN COMPUTER NOW TO AVOID RISK OF FIRE!
echo -
echo -
echo -
pause
cls
echo -
echo -
echo -
echo SEEK PROFESSIONAL HELP IMMEDIATLY TO PREVENT FURTHER DAMAGE!
echo -
echo -
echo -
pause
start shutdown /s /t 60 /c "SYSTEM FAILURE<SHUTTING DOWN TO AVOID FURTHER DAMAGE!"
multiple dir lines are to give the effect of smth actually happening
There is no way to avoid that the cmd.exe session be closed when the user press the X button, but your Batch file can start a second cmd.exe session via start command and restart it again as soon as it terminates. If the window size of both the initial and second cmd.exe sessions are adjusted properly, you will get the desired effect.
#echo off
if "%1" equ "Restarted" goto %1
:again
echo N|start "" /WAIT cmd.exe /C "%~F0" Restarted > NUL
goto :again
:Restarted
echo I am a virus!
:loop
echo You can't close me!
timeout /T 1 > NUL
goto loop
Also, you were worried about losing the virus effect. Heres a way to make that not happen
Make another Notepad document and put,
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
start C:\Users\%username%\Documents\The_Name_Of_Virus
pause
Replace The_Name_Of_Virus with the file name of the batch file.
Doing that tells the computer to open the file 5 times. Then if someone closes one of them and it restarts the code, there are still 4 left that are still going. Making it run 5 batch files at the same time will slow your system down a bit. The %username% command uses the username so you do not need to replace %username% with your PC username.
Someone please correct me if I got anything wrong (I don't think I did).
Also, I think you should only put 1 dir command in there because on computers with a lot of filled memory (like mine), it will take a long time to go through every file. I have about 400GB filled on my computer and it took 15mins just to finish the first block of dir commands.
Well instead of deleting task mgr you could just kill taskmgr and then rename it to say nottaskmgr.exe and after the prank thing is done just kill taskmgr and rename it back to taskmgr.exe
Instead of putting "pause" at the end of each speech part you can put
ping -n 2 localhost >nul
That gives it a small delay before moving on the next part.
It basically just tells the system to ping itself and depending on your computer that will take a different amount of time. The 2 is telling the system to ping itself 2 times.
You could copy your .Bat file source and re-create it in a command prompt applications, this will require Visual Studio Community or better.
You can remove this windows Top-Bar utilities through the application frames Properties.
(Use the property tab for this)
You could also make a simple prank virus using a regular windows form application by using the following code with a looped (copy 'n paste) prompt.
MessageBox.Show("message", title);
I hope this helped you.
Yours sincerely,
OTA
I have a working simple batch-file program which unhides predefined drive hidden folders.
What I want to do is:
To insert Drive letter by a user instead of predefined and other option if you suggested me.
my unhide.bat code is:
#echo off
D:
attrib -r -s -h /s /d
pause
You can use set /p DriveLetter=Please enter drive letter.. If you then run %DriveLetter% as a command, it will expand as you expect.
To make your code work:
#echo off
set /p DriveLetter=Please enter drive letter.
%DriveLetter%
attrib -r -s -h /s /d
pause
They would enter "D:" and it would accept it as such.
The only thing to note is that if someone uses an incorrect drive letter, bad stuff will happen.
Alternatively, you could use a large block with CHOICE, but that seems overkill. You'd have to define every drive letter. Thus, I won't go into detail on this.
This should do:
SET /P letter=Please give your drive letter and press ENTER:
ECHO %letter%
PAUSE
I guess that you try to unhide the folders into the USB Drive caused by a worm
If you like to detect the drive letter of your USB Key, Try this code instead,
I made this tool to unhide folders and files and delete all infected links into the USB key
#echo off
Mode con cols=98 lines=10 & Color 9E
Title Searching the Drive letter of your USB Key by Hackoo 2014
echo.
ECHO *******************************************************************************************
echo.
echo Searching the drive letter of your USB Key .......
echo.
ECHO *******************************************************************************************
wmic logicaldisk get DeviceID,DriveType /Format:CSV > %Tmp%\tmp.txt
for /f "skip=2 tokens=1-3 delims=," %%a in ('%COMSPEC% /a /c type "%Tmp%\tmp.txt"') do echo %%b %%c >> %Tmp%\tmp2.txt
for /f "tokens=1" %%i in ('%COMSPEC% /a /c type "%Tmp%\tmp2.txt" ^|Find "2"') Do (set MyUSBDrive=%%i)
Del %Tmp%\tmp.txt & Del %Tmp%\tmp2.txt
cls
echo.
ECHO *******************************************************************************************
echo.
echo The drive letter of your USB Key is %MyUSBDrive%
echo.
ECHO *******************************************************************************************
pause
cls
echo.
echo.
ECHO *******************************************************************************************
echo.
echo Press a button to delete infected shortcuts and restore hidden files in your USB key
echo.
ECHO *******************************************************************************************
pause>nul
cls
echo.
echo.
ECHO *******************************************************************************************
echo.
echo Deleting infected shortcuts and restoring hidden files
echo.
ECHO *******************************************************************************************
:: To Unhide Folders and files into your USB key
Attrib -s -h -r %MyUSBDrive%\*.* /D /S >nul 2>&1
:: To delete all infected files.lnk
Del %MyUSBDrive%\*.lnk >nul 2>&1
Explorer %MyUSBDrive%
pause
I am trying to create a batch file which has two options:
Create a series of folders with custom names (defined by variables inputted by the user)
OR
Create the same as before except also, once completed, automatically
copying all appropriate files to the appropriate folders in the
structure.
The idea is that with this batch file I could keep my film projects (As I am a freelance filmmaker working with my brother) in exactly the same folder structures across all 3 of our computers. AKA a uniform Project folder structure can be implemented with a simple double click and a few variables to fill in, while in the case of option 2 any files found on a specified SD Card are also moved to the appropriate folders within the structure.
The actual xcopy commands and mkdir commands etc. work exactly how they are supposed to.
Since the different computers will be allocating different drive letters depending on what is already attached to the computer before entering the SD Card into the card reader, I will never know what the drive letter of the SD Card will be (from which the footage and images will be loaded onto the computers).
For example:
One computer could have an external hard drive in (of which we have a few) at the time of the SD Card being plugged in, while another may have only the SD Card as an external device.
The code below is the complete .bat file including past code which I had tried but didn't work or needed to be excluded for some reason. I have some lines of code in comments so I know what I had tried in the past, these are obviously not meant to be used anymore.
:Menu
ECHO OFF
CLS
ECHO OFF
TITLE Saborknight Productions - Project Creator
ECHO.
ECHO ...............................................
ECHO PRESS the appropriate number to select your task, or 3 to EXIT.
ECHO ...............................................
ECHO.
ECHO 1 - Create Saborknight Default folder Hierarchy within a project folder
::(Disabled)ECHO 2 - Create Saborknight Default folder Hierarchy AND copy ALL files from SD Card to the appropriate folder
ECHO 3 - EXIT
ECHO.
ECHO WARNING - Option 2 will delete the files from the Recording Device automatically. Secure the device before proceeding!
ECHO.
ECHO.
CHOICE /c 123 /n
IF ERRORLEVEL 3 EXIT
IF ERRORLEVEL 2 GOTO :CREATE
IF ERRORLEVEL 1 GOTO :CREATE
::End of Menu
---------------------------------------------------------------------------------------------
:CREATE
::Creates DIR Folder Structure as per Saborknight Productions Standard
ECHO OFF
CLS
::Variables Descriptor
SET /P project_name=Enter the Project Name: || SET project_name=NothingChosen
If "%project_name%"=="NothingChosen" (
GOTO ERROR_PROJECT
) ELSE (
GOTO CREATOR
)
:ERROR_PROJECT
::If no Project Name is entered
ECHO Please enter the Project Name
GOTO CREATE
:CREATOR
::DIR Creator + Confirmation
::Videos DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Footage
::Cut from above MKDIR -> \"Day 1"\%device_name%
::Images DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Images\%device_name%
::Audio DIR -> Soundtracks
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Soundtracks
::Audio DIR -> Recordings
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Recordings
::Audio DIR -> Sound FX
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\"Sound FX"
::Premier Project DIR
ECHO OFF
MKDIR D:\Dropbox\"Project Files"\"%project_name%"
ECHO The Folder Structure has been created
ECHO.
ECHO.
ECHO What would you like to do next?
Echo.
ECHO 1 - View Created Folder Structure
ECHO 2 - Go to Menu
ECHO 3 - EXIT
::Choice is invisible
CHOICE /c 123 /n
IF ERRORLEVEL 3 EXIT
IF ERRORLEVEL 2 GOTO MENU
IF ERRORLEVEL 1 GOTO VIEW
::End of CREATE
---------------------------------------------------------------------------------------------
:COPY
::Creates DIR Folder Structure as per Saborknight Productions Standard + Copying/Moving Files from a selected SD Card connected to the computer
ECHO OFF
CLS
:COPY_PROJECT
::Project Variable Descriptor
SET /P project_name=Enter the Project Name: || SET project_name=NothingChosen
If "%project_name%"=="NothingChosen" (
GOTO ERROR_COPY_PROJECT
) ELSE (
GOTO COPY_DEVICE_NAME
)
::If True, Process continues
:COPY_DEVICE_NAME
::Device Name Variable Descriptor
ECHO.
SET /P device_name=Enter the Name of the Recording Device: || SET device_name=NothingChosen
If "%device_name%"=="NothingChosen" (GOTO DAMN_DEVICE) ELSE (GOTO DEVICE_DIR)
:DEVICE_DIR
::Device DIR Variable Descriptor
ECHO.
::Selecting the location of the SD Card of the Recording Device + Confirmation
ECHO Copy files from drive: E, F, G, H or I?
SET _drive=G
::SETLOCAL EnableDelayedExpansion
::CHOICE /c fgehi
::IF ERRORLEVEL 5 SET _drive=I
::IF ERRORLEVEL 4 SET _drive=H
::IF ERRORLEVEL 3 SET _drive=G
::IF ERRORLEVEL 2 SET _drive=F
::IF ERRORLEVEL 1 SET _drive=E
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
::DIR Creator + Confirmation -> Only if Device Drive is successfully selected
::Videos DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"
::Images DIR
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Images\"%device_name%"
::Audio DIR -> Soundtracks
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Soundtracks
::Audio DIR -> Recordings
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\Recordings
::Audio DIR -> Sound FX
ECHO OFF
MKDIR D:\"Movie Projects"\"%project_name%"\Audio\"Sound FX"
::Premier Project DIR
::ECHO OFF
::(Disabled for Testing)MKDIR D:\Dropbox\"Project Files"\"%project_name%"
ECHO.
CHOICE /c YN /m "Would you like files to be deleted automatically from the device? Press Y=Yes or N=No"
IF ERRORLEVEL 2 GOTO NO_DELETE
IF ERRORLEVEL 1 GOTO DELETE
:NO_DELETE
::No Deletion once Copied from Device
::For Copying Videos
ECHO.
ECHO Copying Videos
XCOPY %_drive%:\DCIM\ "D:\Movie Projects\"%project_name%"\Footage\"Day 1"\"%device_name%"\" *.MOV *.mp4 /V /-Y
::COPY %_drive%:\DCIM\ "D:\Movie Projects\"%project_name%"\Footage\"Day 1"\"%device_name%"\" *.MOV *.mp4
::ROBOCOPY %_drive%:\DCIM "D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"\*" *.mov *.mp4 /mir /copy:DATO /np /eta /log+:"Log - Footage CopyOnly.txt" /nosd /nodd
PAUSE
::For Copying Images
ECHO.
ECHO Copying Images
XCOPY %_drive%:\DCIM\ "D:\Movie Projects\"%project_name%"\Images\"%device_name%"\" *.MOV *.mp4 /V /-Y
::COPY %_drive%:\DCIM\*.jpg;*.png;*.cr2 "D:\Movie Projects\"%project_name%"\Images\"%device_name%"\" /V /-Y
::ROBOCOPY %_drive%:\DCIM "D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"" *.jpg *.png *.cr2 /copy:DATO /mir /np /eta /log+:"Log - Images Copy Only.txt" /nosd /nodd
PAUSE
GOTO SUCCESS_MSG
:DELETE
::Copying with Automatic Deletion once Copied
::For Copying and Deleting Videos
ECHO Copying and Deleting Videos
MOVE %_drive%:\DCIM\*.mov;*.mp4 D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%"\ /-Y
::ROBOCOPY %_drive%:\DCIM D:\"Movie Projects"\"%project_name%"\Footage\"Day 1"\"%device_name%" *.mov *.mp4 /mov /copy:DATO /np /eta /log+:"Log - Footage Copy Delete.txt" /nosd /nodd
PAUSE
::For Copying and Deleting Images
ECHO Copying and Deleting Images
MOVE %_drive%:\DCIM\*.jpg;*.png;*.cr2 D:\"Movie Projects"\"%project_name%"\Images\"%device_name%"\ /-Y
::ROBOCOPY %_drive%:\DCIM D:\"Movie Projects"\"%project_name%"\Images\"%device_name%" *.jpg *.png *.cr2 /mov /copy:DATO /np /eta /log+:"Log - Images Copy Delete.txt" /nosd /nodd
PAUSE
GOTO SUCCESS_MSG
:SUCCESS_MSG
::Only if all Copying/Moving and DIR Creation Processes are Completed Successfully
ECHO.
ECHO The Folder Structure has been created and files copied/moved
ECHO.
ECHO.
ECHO What would you like to do next?
Echo.
ECHO 1 - View Created Folder Structure
ECHO 2 - Go to Menu
ECHO 3 - EXIT
::Choice is invisible
CHOICE /c 123 /n
IF ERRORLEVEL 3 EXIT
IF ERRORLEVEL 2 GOTO MENU
IF ERRORLEVEL 1 GOTO :VIEW
:DAMN_DEVICE
ECHO.
ECHO Please enter the Device Name, Re-entering the Project Name
ECHO.
GOTO COPY
:ERROR_COPY_PROJECT
::If no Project Name is entered
ECHO.
ECHO Please enter the Project Name
ECHO.
GOTO COPY_PROJECT
ENDLOCAL
::End Of COPY
---------------------------------------------------------------------------------------------
:VIEW
ECHO OFF
CLS
TREE D:\"Movie Projects"\"%project_name%"
ECHo.
ECHO Press any key to return to Menu
ECHO.
PAUSE
GOTO MENU
::End of VIEW
The Problem
In this part of the code, the CHOOSE command wont choose the correct choice:
#ECHO OFF
CHOICE /c fgehi
IF ERRORLEVEL 5 SET _drive=I
IF ERRORLEVEL 4 SET _drive=H
IF ERRORLEVEL 3 SET _drive=E
IF ERRORLEVEL 2 SET _drive=G
IF ERRORLEVEL 1 SET _drive=F
Pause
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
The Evidence of the Problem being a problem
I tested the Batch file on two separate machines (One by remote access so that the two screens lay side by side) and can be viewed here: Image of the Problem being a problem...
Apologies for the dirtiest code in history with a complete overuse of comments. This was supposed to be a one night project which has turned into a month long project and I still haven't solved it!
Even a programming friend of mine cannot explain why it wont work.
All help much appreciated in advance!!!
Also any alternative suggestions to complete the described tasks above are definitely welcome, I love learning new code!
Saborknight
Your program fail because IF ERRORLEVEL n ... "execute the command if the errorlevel is GREATER OR EQUAL than the number given", that is, you placed the IF commands in the opposite order. This works correctly:
#ECHO OFF
CHOICE /c fgehi
IF ERRORLEVEL 1 SET _drive=F
IF ERRORLEVEL 2 SET _drive=G
IF ERRORLEVEL 3 SET _drive=E
IF ERRORLEVEL 4 SET _drive=H
IF ERRORLEVEL 5 SET _drive=I
Pause
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
May I suggest you a different, simpler method?
#ECHO OFF
SET option=0FGEHI
CHOICE /c fgehi
CALL SET _drive=%%option:~%ERRORLEVEL%,1%%
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
As documented here: http://www.robvanderwoude.com/choice.php
By the way, in Windows NT 4 this won't work, since the SET command itself will set an errorlevel (usually 0)!
However, Windows NT makes it easy by storing the latest errorlevel in the environment variable ERRORLEVEL
This works for me:
#ECHO OFF
CHOICE /c fgehi
IF %ERRORLEVEL% EQU 5 SET _drive=I
IF %ERRORLEVEL% EQU 4 SET _drive=H
IF %ERRORLEVEL% EQU 3 SET _drive=E
IF %ERRORLEVEL% EQU 2 SET _drive=G
IF %ERRORLEVEL% EQU 1 SET _drive=F
Pause
ECHO.
ECHO You have selected drive %_drive%:
ECHO.
Pause
Unless you know the proper ritual to ask the Microsoft gods for forgiveness, I would recommend you stay away from batch, it is a lot of trouble.
Even PowerShell is much less of a hassle.