Batch Script - OverviewBatch Script is incorporated to automate command sequences which are repetitive in nature. Scripting is a way by which one can alleviate this necessity by automating these command sequences in order to make one’s life at the shell easier and more productive. S.No.Options & Description1./S systemSpecifies the remote system to connect to2./UdomainuserSpecifies the user context under which the command should execute.3./P passwordSpecifies the password for the given user context. Prompts for input if omitted.4./FIFilterNameApplies a filter to select a set of tasks.
Allows '.' to be used. Imagename eq acme. See below filters for additional information and examples.5./PIDprocessIDSpecifies the PID of the process to be terminated. Use TaskList to get the PID.6./IMImageNameSpecifies the image name of the process to be terminated. Wildcard '.' can be used to specify all tasks or image names.7./TTerminates the specified process and any child processes which were started by it.8./FSpecifies to forcefully terminate the process(es).Examplestaskkill /f /im notepad.exeThe above command kills the open notepad task, if open.taskill /pid 9214The above command kills a process which has a process of 9214.
Starting a New ProcessDOS scripting also has the availability to start a new process altogether. This is achieved by using the START command.
SyntaxSTART 'title' /D path options 'command' parametersWherein.title − Text for the CMD window title bar (required.).path − Starting directory.command − The command, batch file or executable program to run.parameters − The parameters passed to the command.Following are the description of the options which can be presented to the START command. S.No.Options & Description1./MINStart window Minimized2./MAXStart window maximized.3./LOWUse IDLE priority class.4./NORMALUse NORMAL priority class.5./ABOVENORMALUse ABOVENORMAL priority class.6./BELOWNORMALUse BELOWNORMAL priority class.7./HIGHUse HIGH priority class.8./REALTIMEUse REALTIME priority class.ExamplesSTART 'Test Batch Script' /Min test.batThe above command will run the batch script test.bat in a new window. The windows will start in the minimized mode and also have the title of “Test Batch Script”.START ' 'C:Program FilesMicrosoft OfficeWinword.exe' 'D:testTESTA.txt'The above command will actually run Microsoft word in another process and then open the file TESTA.txt in MS Word. Batch Script - AliasesAliases means creating shortcuts or keywords for existing commands.
Batch File Add Path Environment Variable
Suppose if we wanted to execute the below command which is nothing but the directory listing command with the /w option to not show all of the necessary details in a directory listing.Dir /wSuppose if we were to create a shortcut to this command as follows.dw = dir /wWhen we want to execute the dir /w command, we can simply type in the word dw. The word ‘dw’ has now become an alias to the command Dir /w.
Set Variables In Batch File
Creating an AliasAlias are managed by using the doskey command. SyntaxDOSKEY options macroname=textWherein.macroname − A short name for the macro.text − The commands you want to recall.Following are the description of the options which can be presented to the DOSKEY command.