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
Related
I'm trying to make my own Command Prompt with a Batch-File with a custom commands like "Remove" as "Del" command etc... But when i came across the User input i faced a problem and here it is:
CMD.bat
#echo off
echo.
set /p inp=Command:
if /i %inp% == Remove ...
...
And i stopped to think, "How do i will make a Remove command?". So what i want to do is making a "Remove" command to use it like this "Remove C:\Users\usr\Desktop\File.txt" but if the user typed another thing like Remove blablabla, how the program will detect that the command syntax is incorrect?.
So if anyone Found a solution i will be very appreciated, And Thanks!
Assuming that you are asking how to set custom commands, try this.
#echo off
set "RESPONSE="
goto 'input'
: 'input'
set /p response=What would you like to do?
if /I %response%==help goto 'help'
set /p responsetwo=What would you like to %response%?
if /I %response%==remove set response=del
if /I %response%==check set response=dir
if /I %response%==dir %response% "%responsetwo%"
%response% %responsetwo%
echo %response% "%responsetwo%"
goto 'input'
: 'help'
cls
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
pause
goto 'input'
To add anymore custom commands, simply add
if /I %response%==<word you want to do X command> set response=<X command>
(Replace X with command for second code piece, obviously.)
EDIT: Okay, so after reading your comment I came up with a better solution. Here you go!
#echo off
goto 'input'
: 'input'
cls
set "response="
set /p response=What would you like to do?
set firstresponse=%response:~0,5%
if %firstresponse%==help goto 'help'
pause
if /I %firstresponse%==check set firstresponse=dir && set executeparttwo=%response:~5%
if /I %firstresponse%==remov goto 'remove'
rem Put "if /I %firstresponse%==<whatever the first 5 letters of the command would be> goto '<command name>'
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'remove'
set "firstresponse=" && set firstresponse=%response:~0,6%
if /I %firstresponse%==remove set firstresponse=del
set executeparttwo=%response:~6%
%firstresponse%%executeparttwo%
pause
goto 'input'
: 'help'
cls
echo Check = Dir in regular command prompt, checks a directory.
echo Remove = del in regular command prompt, deletes something.
pause
goto 'input'
use the doskey command heres what you would put
doskey del=remove
#echo off
md C:\Users\%username%\Documents\"Backuped Minecraft Mods"
echo C:\Users\%username%\Documents\Backuped Minecraft Mods\Backups > C:\Users\%username%\Documents\"Backuped Minecraft Mods"\path.txt
set /p mpath=<"C:\Users\%username%\Documents\Backuped Minecraft Mods\path.txt"
echo %mpath%
tree /f %mpath%
pause
This is a part of bat file which I am making,
but I there is a problem in command "tree /f %mpath%", I think.
When I run this, there is a error massage which says-
매개 변수가 너무 많습니다 - Minecraft
매개 변수가 너무 많습니다 is "Too many parameters" in English.
I used only ONE parameter in tree command so why "Too many parameters"?
Here's some example code for you.
Echo Off
Set "bpath=%UserProfile%\Documents\Backuped Minecraft Mods"
Set "mpath=%bpath%\Backups"
Set "tpath=%bpath%\path.txt"
If Not Exist "%bpath%\" MD "%bpath%"
(Echo=%mpath%)>"%tpath%"
Rem Set /P "mpath="<"%tpath%"
Tree /F "%mpath%"
Pause
I've Remarked line 9 which isn't required in the provided context of your snippet.
As I stated above Psshutdown refuses to work in a batch file but works fine in a command prompt. The script has some light logic to determine what group of PCs and such. Here is the script:
#ECHO OFF
cd "C:\temp\remote enable rdp"
goto :SET
:SET
set /p groupPC=pc or list?:
if %groupPC% == pc goto :PC
if %groupPC% == list goto :LIST
goto :SKIP
:PC
ECHO[
set /p pcName=Which PC?:
psshutdown -c -k \\%pcName% -r
PAUSE
goto :DONE
:LIST
ECHO[
set /p input=Which list?:
set list=%input%.txt
psshutdown #C:\Temp\Lists\%list% -r -f else goto :SKIP
PAUSE
goto :DONE
:SKIP
ECHO[
ECHO You probably typed something wrong. Starting from the top.
PAUSE
ECHO[
goto :SET
:DONE
ECHO Mischief Managed
TIMEOUT /t 10
EXIT /B
Every time I run either the PC logic or the List logic the prompt merely shows me the psshutdown syntax uses. I have tried every configuration of syntax I can find on the internet. Any thoughts?
Edit:It's worth noting that the #file syntax I'm using works almost verbatim with psexec.
Two things stand out to me. If your filename has a space in it, that would produce the results you mentioned. Try putting quotes around the file path.
I also can't make sense of the "else" statement at the end of your line. Was that a mistake? It should work with the below line instead.
psshutdown #"C:\Temp\Lists\%list%" -r -f
fun stuff!!
Manager has just bought a humdinger of a utility. It does everything. It even has command line functionality. If you run BugFixer /a the application will automatically scan the entire drive for cooties. If you run the Bugfixer /b it will scan all of your files on the Windows\system 32 directory and if you run Bugfixer /c the program will scan and repair your Registry. Need to write a batch file that will allow your users to avoid that pesky GUI and efficiently run the Bug fixer through the command line, by asking them which option they would like to initialize.
:TOP
ECHO WHICH BUG FIXER DO YOU NEED TO RUN? A=ALL B=SOME c=REPAIR
SET /P = %USERSPEC%
IF "%1"=="A=ALL" GO TO :FIRST
IF "%1"=="A=all" GO TO :FIRST
:FIRST
CHKDSK C:
ECHO CHECKING ALL FILES ARE COMPLETE
IF "%2"=="B=SOME" GO TO :NEXT
IF "%2"=="b=some" GO TO :NEXT
:NEXT
CHKDSK /F /R C:\WINDOWS/SYSTEM32
ECHO CHECKING SOME FILES ARE COMPLETE
IF "%3"=="REPAIR" GO TO :LAST
IF "%3"=="repair" GO TO :LAST
:LAST
CHKDSK /c
ECHO REPAIR FILES ARE COMPLETED
Like I said fun stuff. Anyone wanna help?
Next script logic could become helpful:
#echo OFF >NUL
setlocal enableextensions
:TOP
echo(
set "USERSPEC="
set /P "USERSPEC=Which bug fixer do you need to run? A=all B=some C=repair? "
if /I "%USERSPEC%"=="A" goto :FIRST
if /I "%USERSPEC%"=="B" goto :NEXT
if /I "%USERSPEC%"=="C" goto :LAST
echo NO CHECK CHOOSEN, BATCH ENDS
goto :ENDSCRIPT
:FIRST
chkdsk C:
echo CHECKING ALL FILES ARE COMPLETE
goto :TOP
:NEXT
chkdsk /F /R C:\WINDOWS/SYSTEM32
echo CHECKING SOME FILES ARE COMPLETE
goto :TOP
:LAST
chkdsk /c
echo REPAIR FILES ARE COMPLETED
goto :TOP
:ENDSCRIPT
endlocal
goto :eof
However, running it:
==>30019117.bat
Which bug fixer do you need to run? A=all B=some C=repair? a
Access Denied as you do not have sufficient privileges.
You have to invoke this utility running in elevated mode.
CHECKING ALL FILES ARE COMPLETE
Which bug fixer do you need to run? A=all B=some C=repair?
NO CHECK CHOOSEN, BATCH ENDS
==>
Resources (advised reading):
An A-Z Index of the Windows CMD command line (command reference)
Windows CMD Shell Command Line Syntax (additional particularities)
Script resources for IT professionals (a huge Script repository)
So basically I want to create a batch script that can run any notepad file which the user specifies. I tried this...
#Echo Off
SET /P ANSWER=What is the name of the file to open?
IF /i (%ANSWER%)==('FIND /i "*.txt" %ANSWER%) (goto :Filename)
goto :exit
:Filename
Start *.txt
EXIT
:exit
ECHO FAILLLLLLLL
PAUSE
EXIT
The issue here is the first IF statement. I know its wrong. But, I don't know how to specify the entry of any filename. A different way to do this task is also appreciated.
Thanks for help :)
If your goal is simply to open a file that the user specifies in Notepad, the following works for me in Windows 7:
#echo off
set /P answer=What is the file name?
if exist %answer% (
start notepad.exe %answer%
) else (
echo Unable to locate %answer%
)