Complete Batch Programming Chapter 1 | Learn Batch Commands

Actually we will write Batch Commands in batch file programming It is the native programming offered by the Microsoft Windows Operating System. Batch file is created using any text editors like WordPad, Notepad, WinWord or so on, which comprises of a sequence of built-in commands used to perform some often done tasks like deleting a series of files of same type or of different type, creating logs, clearing unwanted craps  from your computer and even for creating a batch VIRUS and much more uses of batch programming. Whenever a Batch program is executed, it was interpreted line-by-line by the CLI (Command Line Interpreter) command.com or the cmd.exe. Batch file is really helpful in automating tedious tasks and for maintaining system logs. The commands used while creating a batch file are case insensitive, in the sense that it may accept both small and upper case letters.

Complete Batch Programming Part 1 | Learn Batch Commands

Modes:

There are two different modes that are supported by DOS (Disk Operating System), they were,

1. Interactive Mode
2. Batch Mode (Silent Mode). 

Interactive mode:

 In interactive mode, when a command is executed, it interacts with the user for input and depending upon the input supplied by the user, the further processes are carried out. For example, let’s take the ‘del’ command.

The ‘del’ command is used for deleting files that reside inside a directory. Now I am going to delete all the files inside a folder named ‘a’, and when I executed the following command, it is interacting with me prompting “Are you sure (Y/N)?”, confirming the deletion operation, and depending upon my input, it decides what to do. If I hit ‘Y’ then it will delete the files specified, else if I hit ‘N’ then it won’t delete.
C:\>del a
C:\a\*, Are you sure (Y/N)? y

Batch Mode:

Batch mode can also be referred as ‘Silent mode’ or ‘Quiet Mode’, and this is mere opposite to the interactive mode. The command that operates at batch mode will never interact with the user at any instance, instead it will take care of every operation by itself.

For example, I am going to explain this by using the same ‘del’ command. There is a switch available for the ‘del’ command, which makes the command to operate at silent mode, and that switch is ‘/Q’
C:\>del /
Q a C:\> 
In this case, the command is not at all interacting with me, whether to delete those file or not

In the above example, I have tried to delete the same files in the same folder by using the same command but with a different switch. Anyhow both the commands will perform the same operation but the mode it operates differs.

How to create a Batch Program:

Complete Batch Programming Part 1 | Learn Batch Commands

As said earlier, batch programs can be written using any of the text editors such as notepad, wordpad and so on, but notepad is the most often used text editor in such cases. Like any other programing languages, lets start our first program with the ‘Hello World’ program.

1. Open up a notepad and type the following.
@echo off
Echo Hello World
pause
2. Save the file with any name you wish, but make sure that you save the file extension with .bat, in this case I am saving this file as ‘first.bat’.
3. When you save the batch file, then the icon becomes.
4. Just double click to execute the batch file that you have created now.
5. You are done!

Let me explain what does the above given program does,

‘echo’ is the command used to print text on the screen, so whatever that follows the echo command will be displayed on the output screen. This command is just like the ‘printf’ statement in the C language.

When you type the echo command alone, then it will tell you whether the ‘echo is ON’ or ‘echo is OFF’. It’s always recommended to turn the echo off, else it will display the prompts like (C:\>) and so on. In order to avoid the prompts being displayed, the echo is turned off by using the command “@echo off” or simply by using the “echo off”.

“Echo Hello World” will display the “Hello World” on the output screen, and the pause command is used to wait for the user interaction, whether to proceed further or not. If the pause is not used, then the batch will terminate immediately after displaying the “Hello World”.

Also Read: Top 4 Password Cracking Techniques | Password Hacking

Internal and External Commands

There are two types of commands that we can run from a command prompt, and they were,

1. Internal commands 
2. External commands. 

Internal Commands

Internal commands are nothing but the built-in commands that are shipped along with the operating system, for example, echo, cls, del, dir were few of the well known internal commands.

External Commands

 External commands are the commands that are often created while installing a new application and these commands mostly have no use except calling that application and support files. Few external commands can only be executed in the ‘Run’ dialog box (start  Run), but not on the command prompt, and those commands include ‘firefox’. The ‘firefox’ command can be executed only from the run line, that too if the firefox application is installed on that machine and it won’t work on the command prompt.

Likewise the ‘firefox’ there are various other external commands such as the “PsTools” which includes commands like, PsExec, PsFile, PsGetSid, PsInfo, PsKill, PsList, PsLoggedOn and so on.

Run Line commands

As said earlier batch file is comprised of sequence of run line commands, hence it’s a must to know at least few useful run line commands for constructing a good batch program. Here I am going to list out the useful run line commands with a brief description.

                          Please Wait Keep Visiting

Batch Operators

Similar to other programming languages, batch program do support various operators for performing operations like arithmetic and logical operations, bitwise AND, OR, NOT, shifting and redirection operation and separators and grouping operators.

Operators                                                         Description
( )                                                                     Grouping
! ~ -                                                                  Unary operators
* / % + -                                                           Arithmetic operators
<< >> < >                                                         Logical shift and re directional operators
&                                                                      Bitwise and
^                                                                       Bitwise exclusive or
|                                                                        Bitwise or
= *= /= %= += -= &= ^= |= <<= >>=             Assignment operators
,                                                                        separator
&&                                                                   For using Multiple commands
||                                                                        For executing one from many commands
The above given were the operators available in Batch file programming for performing arithmetic and logical operations

Let me brief you the operators with a small example

Note : For performing arithmetic operations, the ‘SET’ command should be used along with the ‘/A’ switch.

For performing an addition operation on two integers, then I have to use the below command,
C:\>set /A 5 + 5
As you see in the above example, the ‘set /A’ is used for performing arithmetic operations like addition, subtraction, multiplication and division. The above example is used for performing an addition operation on two integer namely 5 and 5 and gives the output as ‘10’. Similarly you can use the other arithmetic operators.
Example:
The below command is used to subtract 5 from 10.
C:\>set /A 10-5
The below command is used finding the product between 5 and 5.
C:\>set /A 5*5
25 
The below command is for dividing 10 by 5 and displays the output.
C:\>set /A 10/5
The below command is finding the remainder value and this operator is called modulo operator. In this example the remainder value obtained when 11 divided by 5 is 1 and is displayed as output.
C:\>set /A 11%5

Operator precedence:

Likewise other programming languages, batch program does support operator precedence for performing a valid arithmetic operation to obtain accurate results. The precedence of operations are given in order, *, /, %, +, -. The expression that is enclosed and grouped with the grouping operator ‘()’ gets the high priority in the precedence.
C:\>set /A (10-5)*2+6/2 
In the above example, the expression that is enclosed within the ‘()’ operator gets the high priority and thus 10-5 is ‘5’, the next priority moves to the ‘/’ division operator and ‘6/2’ gives ‘3’, then comes the multiplication ‘*’ operator 5*2 gives ‘10’ then it is summed up with ‘3’ to obtain the final result as ‘13’.

To redirect the output of one command to other file, the ‘>’ and ‘<’ command is used. For example the below command is used to print the text “hello redirection” to a notepad file named “first.txt”
C:\>echo hello redirection > first.txt
C:\> 
As we already have seen that the ‘echo’ command is used for printing the given text on the screen, here by using the redirection operator ‘>’ we are redirecting the output of the command to a text file. It will create a new text file even it wasn’t already there. Likewise you can redirect the output of any command to any other files. The below command is used for performing the same operation but the redirection happens to word document,
C:\> echo hello redirection > first.doc
The tilde ‘~’ operator is a unary operator that is used for shortening the long directory names, the following example will brief with the usage of this operator. The tilde operator can be used after 6 consecutive characters of a directory name, for example the “Documents and Settings” is a directory that contains more than 8 characters, instead of typing them all and messing with it, we can use the ‘~’ operator, so that it will automatically recognizes the path and performs the operation mentioned,
C:\>cd C:\DOCUME~1\CYB3RC~1\LOCALS~1\Temp C:\DOCUME~1\CYB3RC~1\LOCALS~1\Temp>  
The above command is just a path to the location “C:\Documents and Settings\Cyb3rcr4wl3r\Local Settings\Temp”, where “Cyb3rcr4wl3r’ is the user account on my computer.

Note: even though the ‘~’ operator is a unary operator, it can’t be used without the 1 following the operator.

The ‘&&’ operator is used to execute multiple commands in a single line, for example, the following command is used to print the text ‘hi’ and ‘hello’ using two different echo commands,
C:\>echo Hi && echo hello
Hi
Hello 
The pipeline operator is used for giving the output of one command as input for another command,
C:\>echo Y | del *.txt   
In the above example, whenever you delete a file using the del command, it will prompt you with a confirmation message whether to delete the file or not, and only depending upon the user input it will proceed further, here we can make use of the pipeline ‘|’ operator to print ‘Y’ when the ‘del’ command prompt for the user interaction.

Whenever the ‘del’ command prompts the user for the confirmation, the output of the echo command (i.e. ‘Y’) will be given as input for the del command, and as a result it deletes all the text files that reside in the specified directory.

Basic Commands

Complete Batch Programming Part 1 | Learn Batch Commands

Here I am going to explain few basic and often used commands used for constructing a simple batch program. Before getting into the commands, there are few thing that I need to explain in detail, and they were ‘sub-commands’, ‘switches’ and ‘parameters’.

Sub-commands:

Sub-commands are nothing but the supportive commands that are used along with the main commands to narrow down the result that we are looking for. For example, I want to view how many user accounts are there created in my computer, and this can be done using the “net” command.

As you can see on your screen, ‘net’ is the main command, where as ‘user’ is the sub-command used for narrowing down the result that we want. A main command can have any number of subcommands and that too depends upon the usage. Once the command gets executed, its displaying all the available user accounts in my computer.

Switches:

Say, for instance i am going to create a new user account in my computer by making use of the “net” command, and the user account that I wish to create is “myname” with password “password” and this can be done using the following command.

As you can see on your screen, ‘switch’ is used again to narrow down the operation of the command that being performed, and most often switches are prefixed with as backward slash ‘/’ or with an hyphen ‘-‘.

The above command have created a new user account named “myname” with the password “password”.

Parameters:

‘Parameters’ can also be referred as ‘command line arguments’ and are nothing but the input supplied to the program by the user while the program is running, and depending upon the parameter the program will proceed the further operation.

Copy the below given code into a notepad and save it as ‘welcome.bat’. Goto command prompt and run the program by using its name “welcome.bat” (Make sure that the ‘welcome.bat’ exists in the directory where you want to run).
@echo off
cd\
echo Welcome %1%
pause  
Where, ‘welcome’ is the batch file name and its followed by the parameter.

Note: You can specify ‘n’ number of parameters for a batch file. Each parameter can be accessed by using the “%number%” format, where you have to replace the ‘number’ with 1 to access the first parameter value, and ‘2’ for accessing the second parameter value and viceversa. Incase if I want to access the file name then it can be access by using %0%, and for accessing the fifth parametes %5% and so on.

‘Help’ is the command that is used to display the available internal commands supported by windows, so that you can type ‘help’ to know the internal commands available on your computer. Each command has its own sub-commands and switches, and to find out the usage of each command in detail, then you may use the ‘/?’ (without quotes) followed by the command, for example, if I want to know what are the available sub-commands and switches for the ‘net’ command, then I can use the ‘net /?’ command to get more details.

Rem:

The ‘rem’ command is used for commenting the source code, so whatever that follows the ‘rem’ was ignored. The ‘rem’ command is often used for commenting large batch programs for easy identification incase of updating of modifications.
@echo off
Rem Program for printing hello world.
Echo Hello World.
Pause
In the above example, the ‘rem’ command is used for commenting the purpose of the program, but its not necessary for this too simple code.

Echo:

As said earlier ‘echo’ command is just like ‘printf’ statement in C programming, this is used to display the text that follows the command on the output screen. Echo command when used alone will display the state, whether it’s turned ON or OFF. By default the echo is turned ON, but it’s always recommended for batch programmers to turn OFF the echo, so that it won’t display the prompts like (C:\>) and so on.

You can turn OFF the echo command by using the command “echo off”, and to turn it ON, you can replace the OFF with ON in the above command.

Color:

The ‘color’ command is used to set the foreground and background color of the command prompt.
Syntax:  
Color background_color_code Foreground_color_code 
 Where,

The “background_color_code” and “ Foreground_color_code” are nothing but the hexadecimal color codes.

If I want to change my command prompt color with black as background and green as foreground, then I can use the following command,
C:\>color a
C:\>color 0a  

Title:

The ‘title’ command is used to set the title of the command prompt. By default the title of the command prompt is set to “C:\Windows\System32\Cmd.exe” incase of windows XP and “C:\Winnt\system32\Cmd.exe” incase of Windows 2000.

Now I wish to change the title to “Its-eHacker”, and this can be done by using the command given below,
C:\>title Its-eHacker

Prompt:

The ‘prompt’ command is used to change the prompt; the default prompt will be the location of the current directory. You can change the prompt as per your wish by using this ‘prompt’ command. The following are the special codes available for the ‘prompt’ command.
$A & (Ampersand)
$B | (pipe)
$C ( (Left parenthesis)
$D Current date
$E Escape code (ASCII code 27)
$F ) (Right parenthesis)
$G > (greater-than sign)
$H Backspace (erases previous cha
$L < (less-than sign)
$N Current drive
$P Current drive and path
$Q = (equal sign)
$S (space)
$T Current time
$V Windows XP version number
$_ Carriage return and linefeed
$$ $ (dollar sign)

Cls:

The ‘cls’ command is used for wiping off the text on the command prompt.

Date:

The ‘date’ command is used for displaying the current date and also for changing the date. When the ‘date’ command is executed alone, then it will prompt you to change the date and when it is executed with the ‘/T’ switch then it will display you the current date.

Time:

The ‘time’ command is used for displaying the current time and also for changing the time. When the ‘time’ command is executed alone, then it will prompt you to change the date and when it is executed with the ‘/T’ switch then it will display you the current time.

Start:

The ‘start’ command is used for starting an application, assigning it with a priority, specifying the memory where to be shared or separated. This command does have its own switches.

Whenever the ‘start’ command is used without any switches, but followed by a string or text, then it is used to start a new command prompt with the text you specified as the title. In the following case, I have used the start command followed by the text “My Shell”, and you can see a new window appeared just right of it with the text “My Shell” specified as title

The ‘/d’ switch is used to specify the start directory of the command prompt, in the following case, I have set the start directory as “C:\windows\system32” using the ‘/d’ switch, and now you can see a new command prompt popping up from the directory “C:\windows\system32”.

The ‘/min’ switch is used for starting a new minimized command prompt, if no application is specified. In the following example, I want a notepad application to be opened in a minimized window
C:\>start /min notepad 
Once this command gets executed you can see the minimized notepad, in the system taskbar.

The ‘/max’ switch is used for starting a new maximized command prompt, if no application is specified. In the following example, I want MSpaint application to be opened in a maximized window.
C:\>start /max mspaint  
Once this command gets executed you can see the MSpaint getting popped up in a maximized window.

The ‘/separate’ switch is used for starting up 16bit programs in a separate memory space. The below command will open up a calculator application in a separate memory.
C:\>start /separate calc  
The ‘/shared’ switch is used for starting up 16bit programs in a shared memory space; hence all the application shares the same memory space. The following command is used for opening up a WordPad in a shared memory space.
C:\>start /shared write  
The ‘/low’ switch when used with the start command is used for starting up an application with the minimal priority (Idle Mode), so that these applications may not be given higher preference. The following command is used to open up a Microsoft office word application with idle mode
C:\>start /low winword  
The ‘/normal’ switch when used along with the start command is used to start an application in a normal mode, which is the default mode for any application getting started. The below command is used to start a new Internet Explorer window with a normal mode.
 C:\>start /normal iexplore.exe
The ‘/high’ switch, when used with the start command will assign high priority for the application that is specified. In the below example, I want the ‘explorer.exe’ to be given the high priority.
C:\>start /high explorer.exe  
The ‘/realtime’ switch assigns a specified application with the real time priority, so that, if this application requires more space for its successful execution, then it will be allocated with the memory space rather than that of the other applications or processes.
C:\>start /realtime ...  
The command will open up the “My Computer” with real priority.

The ‘/abovenormal’ switch is used to assign a process with the priority which stays in between the normal and high priority. The below command is used to open the “Root Drive” with the above normal priority class.
C:\>start /abovenormal ..  
The ‘/belownormal’ switch is used to assign a process with the priority which stays in between the normal and idle. The below command is used to open the “hearts” game with the below normal priority class.
C:\>start /belownormal mshearts.exe  
The ‘/wait’ switch when used with the start command will open up the specified application and waits until the application terminates. The below command will start the ‘tree’ command and waits until the command list out the complete structure of the directory and then will terminates.
C:\>start /wait tree  
The ‘/b’ switch is used to open up a new command prompt on the same console, without popping up a new command prompt. Once you have entered into the new prompt, then its similar to have 2 command prompts, so typing exit will terminate the newly opened command prompt and will not close the entire prompt.

You can see that, I have used the exit command to get rid of the console, but it’s not doing so, but anyhow, I have closed one console and I am working with the other.

Exit:

The ‘exit’ command is used to terminate or close the command prompt.

Call:

 The ‘call’ command is used to call another external batch program. For example, I have created two batch programs namely ‘bat1.bat’ and ‘bat2.bat’, the ‘bat1.bat’ will be able to process up to 5 parameters, where as ‘bat2.bat’ will not support accepting parameters, in such cases, I can use the parent program (bat1.bat) and call the child program (bat2.bat) to make the child program to accept the parameters.

Tasklist:

The ‘tasklist’ command is used display all the processes that are currently running in the background along with the PID (Process ID), session name, session and memory usage. This command too has its own sub-commands and its switches to narrow down the result that we are looking for.

When the ‘tasklist’ command without supplying any switches and sub-commands will list processes running in the background as above.

The ‘/s’ switch is used to specify the remote machine to connect with, the ‘/U’ switch is used for specifying the domain with the username to run the command under the specified user context. In the below example I am going to connect to the machine named ‘node22’ in my LAN, using the below command,
C:\>tasklist /s \\node22 /u administrator /p P4$$w0rd 
The above command will display the processes running on the remote computer “node22” under the user “administrator”.

The ‘tasklist’ command when used with the ‘/M’ switch will display all the .dll (Dynamic Link Library files) associated with the processes running in the background.

The ‘/SVC’ switch when used with the ‘tasklist’ command is used to display the services associated with the processes running in the background.

If you are not aware of the services, then you may have a lot at ‘services.msc’ and it will display all the services available in your computer.

The ‘/V’ switch is used for displaying the verbose information about the processes running in the background.

The ‘/FI’ switch is used to filter the result according to the filters and conditions used.

The valid operators are nothing but the short terms for the precise words given below,
Eq equals
Ne Not Equals
Gt Greater than
Lt Lesser than
Ge Greater than and equals
Le Lesser than and equals 
Now let’s see, how to use the ‘/FI’ switch effectively,

The following command will list all the processes that are “Not responding”.
C:\>tasklist /FI "status eq not responding"  
The below command will list all the processes that are currently running,
C:\>tasklist /FI "status eq running”  
The following command will filter the processes whose PID is less than 1000 and will display them on the screen,
C:\>tasklist /FI "pid lt 1000"  
The below command will filter the processes running in the background using the session number ‘0’, by default the session number of the currently logged in local user is ‘0’, hence it will display all the processes,
C:\>tasklist /FI "session eq 0"  
The below command will display all the processes whose CPU time is greater than 00:00:00 (Hr:Min:Sec).
C:\>tasklist /FI "cputime gt 00:00:00"  
The following command will display all the processes running in the background which occupies more than 10000 Kilobytes of memory,
C:\>tasklist /FI "memusage gt 10000"  
The below command will filter and display all the processes running in the background except the “explorer.exe”,
C:\>tasklist /FI "services ne explorer.exe" 
The below command is used to display all the background running processes, which are not running under the username “myname”
C:\>tasklist /FI "username ne myname" . 
The below command is used to display all the processes that except the process that are associated with the services “themes” and “server”
C:\>tasklist /FI "services ne themes" /FI "services ne server"  
The below command will display the applications that has the window title “untitle*”, here I have used the * - asterisk as the wildcard for filtering.

C:\>tasklist /FI "windowtitle eq Untitle*"
Image Name             PID Session Name                Session#                Mem Usage
========================= ====== ============================
notepad.exe                   2344 Console                         0                         3,120 K  
The following command will display the background processes by filtering whose processes are associated with the “winsta.dll” module.
C:\>tasklist /FI "modules eq winsta.dll"  
The following command is used to connect to the remote machine named “productionserver”, by using the username “administrator” with password “$3cr3t” and will filter the processes, which are occupying more than 15000 Kb memory, and whose window title says “Untitled*”.
C:\>tasklist /S //productionserver /U administrator /P $3cr3t /FI "memusage gt 15000" /FI “windowtitle eq Untitled*" 

Taskkill:

The ‘taskkill’ command is used to terminate the specified processes both locally and remotely. This command does too have lot of switches and filters, and only few differs from the ‘tasklist’ command, and most of the switches were similar and operates the same like the ‘tasklist’ switches.

The following command is used to connect to the remote host with the IP address 10.199.64.66 by using the username “myname” with the password “password” and terminate the process that has the name “soundmix.exe”.
C:\>taskkill /S 10.199.64.66 /U myname /P password /im soundmix.exe 
When you notice the above command, the switch used for connecting to the remote host ‘/S’, and the switches used for supplying the username and password ‘/U’ and ‘/P’ respectively was the same in the ‘tasklist’ command. The only switch that differs in the above command is the ‘/im’ which is used to specify the Image name (Process Name).

The ‘/F’ switch is used for forcibly terminate the specified process. The below command is used for forcibly terminating the process “userinit.exe” in the local machine.
C:\>taskkill /f /im userinit.exe  
The ‘/PID’ switch is used to terminate the process using the specified PID (Process ID), the following command is used to terminate the process, which have got the PID number 556.
C:\>taskkill /f /PID 556  
If the process specified is a system process, then you will be displayed an error.
In this case, the specified process is a critical system process;

The ‘/T’ switch is used to terminate all the threads and child processes associated with the specified process to kill. The following command is used to kill the process “fun.exe” forcibly along with its child processes on the local machine.
C:\>taskkill /f /im fun.exe /t 
The filter switch ‘/FI’ is similar to the filter switch in the tasklist command, anyhow lets see few example, on how to effectively terminate processes by filtering it.

The below command is used to connect to the remote machine with IP address 10.199.64.66 with username “us3rnam3” and password “passwords” and to kill the process whose process name is “remoteshell.exe”, and the processes which have got the PID numbers 1524, 2415 and 995, and the process that occupies more than 20000 Kilobytes of memory.
C:\>taskkill /S \\10.199.64.66 /U us3rnam3 /P passwords /IM remoteshell.exe /PID 1524/T /PID 2415 /T /PID /T 995 /t /FI “memusage gt 20000” /T

Label:

The ‘Label’ command is used to create, modify or delete the volume label of the disk. The below command is used to name the Label of C: drive as “Root Drive”.
C:\>label Root Drive 
In case, if you are in the C: drive and want to change the label of the D drive, then you are supposed to specify the Drive as D.
C:\>label D: Softwares  
You can name the Volume label up to 32 Characters Max.

Tree:

The ‘tree’ command is used to display the current directory structure in a graphical format.


The ‘tree’ command when used with the /F switch will give an elaborate tree structure of the current directory including the files and folders in it.

The ‘/A’ switch is used to display the ASCII characters instead of extended characters.

Ver:

The ‘ver’ command is used to display the Windows XP version, and this command doesn’t have any switches.
C:\>ver
Microsoft Windows XP [Version 5.1.2600] 

Type:

The ‘type’ command is used for displaying the contents of a file, and this command too doesn’t have any subcommands or switches. If I want to read the text from a text file ‘userlist’ without opening it in a separate window, then I can use the below command,
C:\>type userlist.txt

Shift:

The ‘shift’ command is used for shifting the parameter given as input by one position down. This command is useful only if your batch program accepts parameters from the user. The following example will clearly brief you how this command works,
@echo off
Echo Before shifting.
Echo first parameter : %1%
Shift
Echo After shifting.
Echo first parameter : %1%
Pause
I have saved the above program as ‘test.bat’ on my C drive, and I have supplied two parameters namely ‘a’ and ‘b’.

After shifting, the first parameter gets the value of the second parameter and vice versa.

Pause:

The ‘pause’ command is used to suspend the process of the batch program, and will wait for the user interaction, and depends upon the user interaction the command will proceed further. When the pause command is executed, then it will display the message “Press any key to continue . . .”.

Convert:

The ‘convert’ command is used to convert a volume from FAT(File Allocation Table) file system to NTFS (New Technology File System) even without formatting or doing any major changes. The below command will convert the C: drive from FAT to NTFS.
Convert C: /FS:NTFS 
Where,
Convert - Command
C: - Drive that you want to convert
/FS - Switch stating the File System
NTFS - NTFS (New Technology File System) 

Just by using the above command, you can easily convert any Drive from FAT or FAT32 to an NTFS Partition, even without formatting. Remember that this is a One way process, you can change from FAT/FAT32 to NTFS and you can’t revert back from NTFS to FAT/FAT32. NTFS includes a lot of features like compression and encryption providing both security and optimizing memory, also includes fast indexing and can use features such as Active Directory.

Shutdown:

The ‘shutdown’ command is used to shutdown, logoff or reboot the specified machines both locally and remotely. The shutdown command comes along with few switches that decide the operation to be done.

The ‘-a’ switch when used with the shutdown command used to abort the machine from shutting down. For example, if you have already initiated a shutdown, you can abort the operation using the below command,
C:\>shutdown –a 
The ‘-S’ switch is used to specify the machine to shutdown, where as the ‘-r’ is used to reboot the machine and ‘-l’ switch is used to log off the currently logged user

The ‘-t’ switch is used to specify the time to wait, to perform the operation mentioned. The arguments supplied to the ‘-t’ switch can only be accepted in seconds, for example, if I wish to turn off my computer after 60 seconds (1 Minute), then I can use the following command to do so,
C:\>shutdown –s –t 60  
The ‘-c’ switch is used for displaying comments in the output window (dialog box). This switch is often used to convey the reason for the shutdown or reboot. For example, if I have turned off all the computers connected in the LAN for updating software’s, then I may use the ‘-c’ to convey this message as the reason by using the below command,
C:\>shutdown –s –t 85 –c “This is a Temporary shutdown for updating the production softwares, and machines will be up soon” 
The above given command is only applicable for local shutdown.

To remotely shutdown or reboot computers in a LAN, you can do it either by using the GUI (Graphical Remote Shutdown Dialog Box) or by command line.

The ‘-I’ switch is used to open up the “remote shutdown dialog” box, where you can add either the hostnames or the IP addresses of the machines, then you may choose the operation in the given list as “shutdown” or “Log off” or “reboot”, then you may choose the delay time to perform the selected operation, and can specify the comments and can choose the reasons for the operation t be performed.

You can add any number of machines to perform this operation,

I have added four different IP addresses of the computers connected with my Network, and I have selected “restart” the from the menu to reboot those computers after a time period of 45 seconds, and I have made comments that states the reason for the reboot

To perform the same operation using commands alone and not using the GUI, you can use the ‘/m’ switch to connect to the remote computer, for example the following command is used to reboot the remote machine that has the IP address “10.199.64.71”,
C:\>shutdown /m \\10.199.64.71 –r –t 45 –c “This is a temporary reboot, for updating the production software’s, and machines will be up soon.”  
The ‘-f’ switch is used to forcefully terminate all the applications that are currently running on the specified computer, and then will perform the specified operation such as (Logoff, Reboot, Shutdown).

The below command will forcibly terminate all the currently running applications on the local machine and then log off the current user immediately,
C:\>shutdown /f –l –t 00 

At:

The ‘at’ command was helpful is scheduling and automating the tasks at the scheduled time, both on the local machine and on the remote machine. Once the program to run was scheduled, then it will run the program at the specified time, no matter whether the user is there or not, but the machine is supposed to be turned ON.

The ‘at’ command when executed alone without using any subcommands or switches will display the number of schedules tasks and it will display the message “There are no entries in the list.“, if nothing was scheduled to run. Each scheduled task is assigned with an ID number.

To schedule a notepad application to run in the remote machine (10.199.64.66) sharply at 10AM, I can use the below command,
C:\>at \\10.199.64.66 10AM “notepad.exe” 
As you see in the following command, the command successfully has scheduled the “notepad” application to run sharply at 10:00AM tomorrow.
C:\>at \\10.199.64.66 10AM "notepad.exe"
Added a new job with job ID = 1 
When I entered into the command prompt of the remote machine 10.199.64.66, and execute the ‘at’ command I have got the following details,
C:\>at
Status ID        Day             Time                Command Line
-------------------------------------------------------------------
1               Tomorrow       10:00 AM           "notepad.exe"  
As said earlier, each scheduled task is assigned with an ID number, and these ID numbers are used for various purposes like displaying the specified ID information and also for deleting the scheduled task.

Since I know that the task added has the ID number ‘1’, and I am going to test it again, whether the task is added on the remote computer by using the below command,
C:\>at \\10.199.64.66 1
Task ID:          1
Status:             OK
Schedule:        Tomorrow
Time of day:    10:00 AM
Interactive:      No
Command:      "notepad.exe"  
To delete the scheduled task, we have to specify the ID number of the task to be deleted. In the following case I wish to delete the scheduled task that has the ID number ‘1’ by using the below command,
C:\>at 1 /delete 
Even if the scheduled task gets deleted, it won’t display any confirmation message and you have to verify it by again executing the ‘at’ command.

The ‘/yes’ switch is used to delete all the tasks that are scheduled to run, even without any confirmation for deleting.
C:\>at /delete /yes   
The above command will delete all the scheduled tasks.

So far the tasks we have scheduled will run in the background without any user interaction, and to make the tasks run interactively we have use the ‘/interactive’ switch, as below
C:\>at 5:11PM /interactive notepad
Added a new job with job ID = 2 
The above command will run the notepad application at 5:11 PM interactively.

By using the ‘/every’ switch you can specify the application to run in every specified day. In the following example, I have set the application “servermonitor.exe” to run on every 1,10,15,20 and 25th day of every month,
C:\>at 5:22PM /interactive /every:1,10,15,20,25 servermonitor.exe  
The following command is used to schedule and run the application “servermonitor.exe” on next Monday, Tuesday, Thursday, Saturday and Sunday.
C:\>at 5:22PM /interactive /next:M,T,TH,S,SU servermonitor.exe 
Also Read: Top 10+ Famous Hackers In The World
Visit Our Youtube Channel: ALB TechPoint




Disclaimer: All that information given in this Article is only for educational means, and the author of this blog will not hold responsibility for whatever you mess with this stuff.

Thanks for Vsiting
Next Part Is Coming Soon
Keep Visiting
Thanks!

Post a Comment

0 Comments