iamdieter
asked on
Batch file with command box
Good day
Does anyone know how to create a batch file that brings up a a command box with "yes" or "no" answer, and depending on your answer must perform specific command, i.e you have a batch file and when it runs brings up a box asking do you want to copy or cut, if you select copy it must run the "copy" batch file, if you select cut it must run the "cut" batch file.
Urgent help needed please
Does anyone know how to create a batch file that brings up a a command box with "yes" or "no" answer, and depending on your answer must perform specific command, i.e you have a batch file and when it runs brings up a box asking do you want to copy or cut, if you select copy it must run the "copy" batch file, if you select cut it must run the "cut" batch file.
Urgent help needed please
ASKER
Thank you, it works. any posibility of making it a box where users can click instead of type?
Examples: Create batch files in dos eg. helloworld.bat and GoodBye.bat
We can do this by using powershell:
Save the following in cutCopy.ps1
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Do you want to Copy or Cut Operation?", `
0,"Copy or Cut Files",4)
If ($intAnswer -eq 6) {
cmd /c c:\test\helloworld.bat
} else {
cmd /c c:\test\GoodBye.bat
}
The above code calls the batch files depending on selection
Try to run it
We can do this by using powershell:
Save the following in cutCopy.ps1
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Do you want to Copy or Cut Operation?", `
0,"Copy or Cut Files",4)
If ($intAnswer -eq 6) {
cmd /c c:\test\helloworld.bat
} else {
cmd /c c:\test\GoodBye.bat
}
The above code calls the batch files depending on selection
Try to run it
@ECHO OFF
REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
:BEGIN
CLS
REM - THE BELOW LINE GIVES THE USER 2 CHOICES (DEFINED AFTER /C:)
CHOICE /N /C YN /M "TYPE 'Y' IF 'COPY' AND 'N' FOR 'MOVE' (Y or N)"%1
REM - THE NEXT TWO LINES ARE DIRECTING USER DEPENDING UPON INPUT
IF ERRORLEVEL == 2 GOTO TWO
IF ERRORLEVEL == 1 GOTO ONE
GOTO END
:TWO
MOVE /Y [PATH]<SOURCE FOLDERNAME> <DESTINATION FOLDERNAME>
GOTO END
:ONE
COPY <SOURCE> <DESTINATION>
:END
(AND SAVE AS "SOME_NAME.BAT")
REM - LABEL INDICATING THE BEGINNING OF THE DOCUMENT.
:BEGIN
CLS
REM - THE BELOW LINE GIVES THE USER 2 CHOICES (DEFINED AFTER /C:)
CHOICE /N /C YN /M "TYPE 'Y' IF 'COPY' AND 'N' FOR 'MOVE' (Y or N)"%1
REM - THE NEXT TWO LINES ARE DIRECTING USER DEPENDING UPON INPUT
IF ERRORLEVEL == 2 GOTO TWO
IF ERRORLEVEL == 1 GOTO ONE
GOTO END
:TWO
MOVE /Y [PATH]<SOURCE FOLDERNAME> <DESTINATION FOLDERNAME>
GOTO END
:ONE
COPY <SOURCE> <DESTINATION>
:END
(AND SAVE AS "SOME_NAME.BAT")
To run the given code,
Start-> Run -> Powershell (Enter)
Copy paste the following code:
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Do you want to Copy or Cut Operation?", `
0,"Copy or Cut Files",4)
If ($intAnswer -eq 6) {
cmd /c c:\test\helloworld.bat
} else {
cmd /c c:\test\GoodBye.bat
}
Start-> Run -> Powershell (Enter)
Copy paste the following code:
$a = new-object -comobject wscript.shell
$intAnswer = $a.popup("Do you want to Copy or Cut Operation?", `
0,"Copy or Cut Files",4)
If ($intAnswer -eq 6) {
cmd /c c:\test\helloworld.bat
} else {
cmd /c c:\test\GoodBye.bat
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A few techniques discussed here you might want to look at:
http://www.robvanderwoude.com/usermessages.php
In addition, there's a nice little utility called WBAT at the link below that can do this, and more:
http://www.horstmuc.de/ui.htm
~bp
http://www.robvanderwoude.com/usermessages.php
In addition, there's a nice little utility called WBAT at the link below that can do this, and more:
http://www.horstmuc.de/ui.htm
~bp
Another way I use for things is a dynamically created VBScript within the batch file:
Steve
Steve
@echo off
call :askYesNo "Please choose Yes or No" "Title for box"
echo %answer%
if %answer%==6 echo You chose Yes
if %answer%==7 echo You chose No
if %answer%==2 echo You pressed cancel or the X
exit /b
REM call :AskYesNo "Message" "title"
:AskYesNo
set answer=
set vbs="%temp%\getanswer.vbs"
echo wscript.echo MsgBox^("%~1",vbYesNoCancel,"%~2"^)>%vbs%
for /f %%a in ('cscript //nologo %vbs%') do set answer=%%a
exit /b
Open in new window