I have a simple batch file:
ECHO OFF
CLS
ECHO WELCOME
ECHO.
ECHO Launching your app...
What I would like is to return to a default CMD state where the user can type commands, I mean, this state: C:[path][path].....>
I want to give to the user the possibility to continue to type anything he wants after the echo "Launching your app..."
So visually it would give this:
WELCOME
Launching your app...
C:[path][path][path]> _
#echo off
rem check if started from own process (use our own parameter)
rem and if not, spawn a new cmd with correct parameters and
rem keep it open
if not "%~1"=="__startcmd__" (
"%comspec%" /k "%~f0" __startcmd__ %*
exit
)
rem eliminate custom parameter of parameter list
shift
rem your custom screen
cls
title "command window"
prompt $p$g
echo WELCOME
echo Launching your app ...
Related
I'm tryng to write a batch file which starts programs, but two problems arise:
If I use one command, it opens the others (i.e. If I open the calculator, it also opens the curler
Here is the code for my program:
#echo off
cls
title Console
:prompt
set /p prompt=:
goto %prompt%
:help
echo Commands
echo ---------------
echo help........................Shows this list
echo calc........................Starts the CMD Calculator
echo retaskbar...................Starts the Taskbar Fixer
echo curler......................Starts the Curler
echo webping.....................Starts Website Pinger
echo.
pause
goto prompt
:calc
start calc.exe
:retaskbar
start retaskbar.exe
:curler
start curler.exe
:webping
start webping.exe
I'm planning to turn this into a single exe file for more convenience.
I'm finishing off my program, and I've got a basic menu:
echo [1] - New Log Entry
echo [2] - Read Log Entry
echo [3] - Clear Log
echo [4] - Exit
set /p menu=Number:
if %menu%==1 goto NewLog
if %menu%==2 goto Readlog
:::and so on
But I want it to be so that when you type in one of the numbers, it automatically enters the number they put.
I think I've seen it done before but I'm not too sure.
The command CHOICE can be used for taking one of predefined options.
#echo off
:Menu
cls
echo/
echo [1] - New log entry
echo [2] - Read log entry
echo [3] - Clear log
echo [4] - Exit
echo/
choice /C 1234 /N /M "Your choice: "
echo/
if errorlevel 4 goto :EOF
if errorlevel 3 goto ClearLog
if errorlevel 2 goto ReadLog
rem User has taken first choice as being the only remaining choice.
echo Creating new log entry ...
echo/
pause
goto Menu
:ReadLog
echo Reading log entry ...
echo/
pause
goto Menu
:ClearLog
echo Clearing log ...
echo/
pause
goto Menu
The usage of CHOICE is much better than set /P variable=prompt text for such tasks as the user must press one of the offered keys and execution immediately continues once an offered key is hit by the batch file user. set /P gives the user the freedom to enter anything from not entering anything at all up to a very long string containing characters which might result in a syntax error on evaluation of the environment variable value if not extra code is written to make sure that batch file works even for any invalid user input.
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.
choice /?
cls /?
echo /?
goto /?
if /?
pause /?
See also the web pages:
Microsoft's command-line reference
SS64.com - A-Z index of the Windows CMD command line
Testing for a Specific Error Level in Batch Files (Microsoft support article)
What are the ERRORLEVEL values set by internal cmd.exe commands? (Stack Overflow topic)
ECHO. FAILS to give text or blank line - Instead use ECHO/ (DosTips forum topic)
Okay, well, I want to make something like OS... But when I start the .bat file there's a set option for going to help and going to the GUI. I have shortcut with -gsys32 - directly to boot the command. Brhfd... Just take a look if the code, I leave some comments.
#ECHO off
echo GraphicalSystem
echo All rights reserved! 2016
echo PLEASE WRITE help TO OPEN THE HELP WINDOW!
set /p command=
if %command% ==help goto help
if %command% ==gsys32 goto interface
cmd /k
:help
cls
echo gsys32 - Open the graphical interface.
echo exithelp - exit the help
set /p command=
if %command% ==exithelp goto start
cmd /k
:interface
cls
color 17
#ECHO OFF
echo PROGRAMS - GSYS32
echo DRIVE A:\
dir
#ECHO OFF
echo *Write dir /name of the directory without the slashes/*
cmd /k
:start
cls
#ECHO off
echo GraphicalSystem
echo All rights reserved! 2016
echo PLEASE WRITE help TO OPEN THE HELP WINDOW!
set /p command=
if %command% ==help goto help
if %command% ==gsys32 goto interface // I want this to be executed with the shortcut.
cmd /k
And now the shortcut:
So... I want the command from the screenshot to be executed in the code...
Seems to be just a section of the code, so it's difficult to tell.
set "command=%1"
if not defined command goto noparms
if /i "%command%"=="gsys" goto interface
if /i "%command%"=="help" goto help
echo parameter "%1" not recognised&pause
rem don't know what you want to do now...
...
:noparms
rem there were no parameters supplied
....your posted code
%1 accesses the first parameter supplied to the routine.
you would need -gsys in place of gsys if you want to detect -gsys as a parameter. The match is literal (/i option makes it case-insensitive)
It is windows convention that switch-parameters use the format /gsys - but that's a convention, not a rule.
set /p "var=Promptstring" is the general form for accepting keyboard input. Parameters are read using %1..%9
I made a simple batch chat that write the message to an txt file.
I need help with print the file every time it changed and with hidding output.
I used the type, delay and cls to print the file but it didnt work, it didnt printed the file.
launcher.bat:
start cmd /k
call room.bat
call chat.bat
using the launcher photo
room.bat(the problem):
:chat1
cls
TYPE room.txt
timeout /t 0.5
goto chat1
chat.bat(working but show extra info about the os and the file):
#echo off
cls
set D=%Date%
cls
echo enter your name
SET /P name=[name]
pause
:room
cls
SET /P chatpublic=[everyone]
SET "
echo %name%: %chatpublic% |%D%|>> room.txt
pause
goto room
without the launcher photo
Here's the culprit:
echo %name%: %chatpublic% |%D%|>> room.txt
That's because the | vertical line has a special meaning in Windows command line interpreter: commandA | commandB: pipe the output from commandA into commandB.
If you do want use a | vertical line in another sense (e.g. display it with an echo command), then you should escape it as follows:
echo %name%: %chatpublic% ^|%D%^|>> room.txt
I'm trying to write a batch script that will do a RunAs for any given windows service (using explorer.exe to test) for any given user that can be input at time of running. What I currently have is this.
set /p Var1="Domain = "
set /p Var2="Username = "
set /p Var3="Service to open= "
RunAs /user:%Var1%\%Var2% "%Var3%" /seperate
On command line, this seems to work ok (with coded values instead of variables) but in a batch file it just seems to repeat itself, without opening what it's been specified (it doesn't even prompt for a password, so I can only presume its not even trying). Any idea why it's looping and what I can do to stop it?
Cheers
Hi #Gary Barnett i created something similar to this awhile back.
Here is an example;
#ECHO OFF
set /P Domainn=Enter Domain Name:
set /P Usern=Enter Username:
set userunas=runas /user:%domainn%\%usern% "
:optionmenu
CLS
ECHO 1 - Control.exe
ECHO 2 - MSinfo32.exe
ECHO 3 - Explorer.exe
ECHO q - Quit
ECHO.
set /P optionnum=Enter command number:
GOTO option%optionnum%
:option1
%userunas%control.exe
goto optionmenu
:option2
%userunas% %commonprogramfiles%\micros~1\MSInfo\msinfo32.exe"
goto optionmenu
:option3
%userunas%explorer.exe
goto optionmenu
:optionq
EXIT
Note: You must run the batch file as Administrator (right-click -> Run as Administrator) or it wont work.
/seperate is not a switch from RUNAS. So,
RUNAS /USER:"%Var1%\%Var2%" "%Var3%"
should go fine. If /seperate is a parameter to %Var3% program, use:
RUNAS /USER:"%Var1%\%Var2%" "%Var3% /seperate"
You may also add PAUSE at end of script so you can check results, while "debugging".