CMD

 

1. WHAT IS CMD?

 

2. DIFFERENCE BETWEEN GUI AND CLI

 

3. CMD AND POWERSHELL

 

SOME BASIC OPERATION AND COMMANDS REGARDING FILES & FOLDER

OPEN COMMAND PROMPT.

 

DIRECTORY RELATED:

 

CHANGE DIRECTORY (CD)

C:\Users\PC> cd/    [ back to drive]

C:\> cd Users [ enter into Directory]

C:\Users> cd PC [ enter into Directory]

C:\Users\PC> cd .. [ back one step in directory]

C:\Users> cd PC

C:\Users\PC> cd Desktop

 

MAKE DIRECTORY(FOLDER)

C:\Users\PC\Desktop> mkdir pop [ pop Directory created]

 

RENAME DIRECTORY

C:\Users\PC\Desktop> ren pop hip  [ pop directory renamed as hip]

C:\Users\PC\Desktop> cd hip [ enter hip directory]

 

PPT FILE CREATION

C:\Users\PC\Desktop\hip> type nul> fort.pptx [fort is a name of the ppt file]

 

RENAME FILE

C:\Users\PC\Desktop\hip> ren fort.pptx India.pptx [ ren oldFileName NewFileName ]

After doing this, Move it to the Desktop and Make a copy of it in hip directory.

 

COPY

C:\Users\PC\Desktop\hip>  cd..

C:\Users\PC\Desktop> copy india.pptx hip [ Copy OldfileLocation/name NewFileLocation/name ]

1 file(s) copied.

C:\Users\PC\Desktop>  cd hip

 

DELETE FILE

C:\Users\PC\Desktop\hip> del india.pptx [ del fileLocation ]

C:\Users\PC\Desktop\hip> cd..

 

MOVE

C:\Users\PC\Desktop> move india.pptx hip [ move OldfileLocation/name NewFileLocation/name ]

1 file(s) copied.

C:\Users\PC\Desktop>cd hip

C:\Users\PC\Desktop\hip>del india.pptx

C:\Users\PC\Desktop\hip>cd..

 

DELETE FOLDER

 C:\Users\PC\Desktop> rmdir hip [ RMDIR folderLocation/Name ]

C:\Users\PC\Desktop>

 

 

MANAGING TASKS AND SERVICES OF WINDOWS

Task Manager

Open CMD as Administrator.

C:\Windows\system32> tasklist [ all currently running tasks are shown here]

 

START A TASK

C:\Windows\system32> notepad [type software name to start, CALCULATOR: calc]

C:\Windows\system32> tasklist

[ notepad.exe task shown  ]

 

STOP A TASK

C:\Windows\system32> taskkill  /pid 1332  [ 1332 is pid of notepad, check it from the table]

 

CLEAR THE SCREEN

C:\Windows\system32> cls

 

START ALL SYSTEM SERVICES AT ONCE

C:\Windows\system32> net start

 

STOP SYSTEM SERVICES

C:\Windows\system32> net stop “Windows Audio”   [ Sound is Mute, after run it]

 

START SYSTEM SERVICE

C:\Windows\system32>  net start “Windows Audio”    [Sound is Unmute, after run it]

 

INSTALLED DRIVER INFORMATION

C:\Windows\system32>driverquery

// All driver info///

 

 

GETTING SYSTEM & PROGRAMS INFORMATION

OPEN CMD AS ADMINISTRATOR

 

TO SHOW INSTALLED SYSTEM & PROGRAM

 

C:\Windows\system32> wmic [Type WMIC and Enter, type  / output : FilePath  shown below]

wmic:root\cli>/output:D:\insta.txt product get name,version

wmic:root\cli>

[ after getting wmic:root\cli>, open D drive and open insta.txt file. There are all programs and tools installed names and versions are written.]

wmic:root\cli>

 

Close it.

 

 

 

 

CPU INFORMATION

 

C:\Windows\system32> wmic

wmic:root\cli> cpu

/// CPU Information shown here///

 

 

ENTERNAL OR INTERNAL DISK / HARDDISK PROPERTIES

 

C:\Windows\system32> diskpart

DISKPART> list disk

//// DISK STATUS ///

[ Considering, Disk 1 is the pendrive ]

 

DISKPART> select disk 1

DISKPART> detail disk

//// Disk All Information ///

 

DISKPART>

 

Exit from CMD

Open CMD

 

HARDDISK SERIAL NO

C:\Windows\system32> vol D:    [ vol DriveName : ]

// volume drive data and serial no shown here //

 

CHECK DISK

C:\Windows\system32> chkdsk

// Bad file,e t c results displayed //

 

 

MAC ADDRESS

C:\Windows\system32>getmac

// physical address  transport name shown here//

[ every computer/ device has globally unique MAC address]

 

ALL SYSTEM INFORMATION

C:\Windows\system32>systeminfo

// All system configuration shown here, amazing VM also //

 

C:\Windows\system32>

 


MANAGING USER ACCOUNTS

What is User Account?

It is a standard account to run OS BIOS. There are Default and Guest account too. These are disabled by default.

Open run -> type -> lusrmgr.msc -> select users (from left side) -> There are three users (Default, Administrator and Guest shown in middle) -> right click on it -> [ACCOUNT IS DISABLED] is ticked. All standard accounts also shown here.

 

Open CMD (run as administrator)

 

SHOW ALL ACCOUNT

C:\windows\system32> net user   [ type it simple]

// All user accounts are shown here.

 

 

CREATE STANDARD ACCOUNT

 

C:\windows\system32> net user NewUserName /add paaspin    [ paaspin is password ]

The command completed successfully.

C:\windows\system32> net user NewUserName /del   [ this account is deleted]

The command completed successfully.

 

 

ENABLE ADMINISTRATOR ACCOUNT

 

Atfirst, check that, Account is disabled or not. Using Given above code run in RUN SHELL.

 

C:\windows\system32> net user administrator /active:yes      [ Beware of spaces]

The command completed successfully.

C:\windows\system32>

Now, Check it through Switch User. There are Administrator User.

 

DISABLE ADMINISTRATOR ACCOUNT

C:\windows\system32> net user administrator /active:no        [ Beware of spaces]

The command completed successfully.

C:\windows\system32>

Now, Check it through Switch User. There are Administrator User.

Enabling and Disabling Guest and other accounts in this similar way.

 

 

SET PASSWORD

 

Go to Control panel -> User Accounts -> User Account -> Manage Accounts -> Choose the user -> create a password [ Fill this password] then okay. Switch user, Put password -> Open Desktop.

Open CMD.

C:\windows\system32> net user “AccountNAME” * [ “ ”  then * then enter then enter password then enter and password setting successfully completed.]

 

C:\windows\system32>

Now, Check it through Switch User.

 


HIDE & ENCRYPT FILES

Hidden files can be viewed via File-> Change Folder and search options -> Folder Option box open -> Click on show -> select “Show hidden files“ -> OK. And then Hidden file / directory is visible to all of us.

 

Create a folder to put all the files and place some files there.

Open CMD on this folder through the address bar of that folder I.e. ( go to address bar and write CMD)

 

HIDE FILE

C:\Users\PC\Desktop\New folder> attrib +h +r +s    [All files of that folder is hide ]

[ This file is not shown via applying given above method]

 

UNHIDE HIDDEN FILES

C:\Users\PC\Desktop\New folder> attrib -h -r -s   [ All pluses are minuses ]

C:\Users\PC\Desktop\New folder>

 

ENCRYPT

C:\Users\PC\Desktop\New folder> cipher /e [All files are encrypted, A lock comes ]

[ This can be accessible in your machine but not accessible in other machines bcz it is encrypted.]

 

 

DECRYPT

C:\Users\PC\Desktop\New folder> cipher /d [All files are decrypted, A lock goes ]

 

C:\Users\PC\Desktop\New folder> cipher /c [ shows all files ]

C:\Users\PC\Desktop\New folder> cipher /rekey [ Encryption file system key was updated within directory ]

 

 

FILE FORMAT THROUGH EXTENSION

 

C:\Users\PC\Desktop\New folder> assoc.txt

.txt=txtfile

 

C:\Users\PC\Desktop\New folder> assoc.psd

.psd=Photoshop.Image.16

 

C:\Users\PC\Desktop\New folder> assoc.aup

.aup=Audacity.Project

 

All installed software based extension can be found and shown.

 

CREATING & EXPORTING FILES THROUGH CMD

Run CMD as administrator.

 

C:\Windows\System32> cd/

C:\> cd Users

C:\Users>cd desktop


 

FILE EXPORT

 

C:\Users\Desktop> tasklist > file.txt [ after, this arrow > sign is fileName with extension. File Created succssfully.]

C:\Users\Desktop>

Open the “file.txt” file from the Desktop, And Cmd command output is properly shown here.

 

 

FILE EXPORT USING ECHO COMMAND

 

C:\Users\Desktop> echo This text is supplied from CMD > code.txt

C:\Users\Desktop>

Open the “code.txt” file from the desktop and “This text is supplied from CMD” is present.

 

 

COPYCON COMMAND

 

C:\Users\Desktop> copy con Good.txt [ copy con is a file created command ]

Text text text   [ctrl+z and enter  to exit]

1 file(s) copied.

C:\Users\Desktop>

 

 

TYPE COMMAND

 

C:\Users\Desktop>  type good.txt [ Open txt file in CMD prompt]

Text text text  

C:\Users\Desktop> type code.txt

This text is supplied from CMD

C:\Users\Desktop>

 

 

OPEN FILE DIRECTLY

 

C:\Users\Desktop> good.txt [ type the file name and hit enter ]

C:\Users\Desktop>

good.txt file is opened.

 

 

EXPORT FILE USING DIFFERENT EXTENSION

 

C:\Users\Desktop> type nul> ps.psd   [ps.psd file is created ]

C:\Users\Desktop> type nul> hyper.html [html format is created ]

C:\Users\Desktop>

 

 

 

 

 

 


FORMAT, BOOT & LABEL USB COMMANDS

Atfirst, Attach your pendrive into your PC. After that, Run CMD as administrator.

 

FORMAT USB

 

C:\Windows\system32> diskpart [ for disk managing service ]

..

DISKPART> list disk

// Disk related details // let Disk1 is the pendrive.

 

DISKPART>  select disk 1

Disk 1 is not selected disk

DISKPART>  clean

DiskPart succeeded in cleaning the disk.

 

DISKPART> create partition primary

Diskpart succeeded in creating the specified partition.

DISKPART> select partition 1

Partition 1 is not selected partition.

 

DISKPART>  format fs=ntfs quick

 __ percent completed

DiskPart successfully formatted the volume.

 

DISKPART> active

DiskPart successfully assigned the drive letter or mount point.

 

DISKPART> exit

Leaving DiskPart…

 

C:\Windows\system32>

 

 

LABEL USB

 

C:\Windows\system32> label E     [ ‘E’ means the letter of the USB drive shown in PC for example E]

[ Enter your USB name in Volume label: and hit ENTER]

 

C:\Windows\system32>

 

 

BOOTABLE USB

 

C:\Windows\system32>

[ After formatting step, Go the image file location, Right click on the ISO file and mount it. After that, Go to My Computer, Open new ISO CD drive, open it, copy all files and paste it in Your USB flash drive. ]

 

Your USB is not bootable USB.

 


HOTSPOT PASSWORD & NETWORK COMMANDS

If you use a PC, then You can buy a Wi-Fi device( I.e. Celrax Wi-Fi Receiver 300Mbps, 2.4Ghz, 802.11B/G/N USB 2.0 Wireless Wi-Fi Network Adapter or Viboton USB Wifi Adapter 950mbps,  Wireless network receiver Dongle for Desktop PC laptop.)

 

Open CMD and Run as administrator mode.

Our basic Wifi Connectivity name is h04x.

 

WI-FI DETAILS

 

C:\Windows\system32> netsh wlan show profiles

Profiles on interface Wi-Fi:

// Wi fi details //

 

C:\Windows\system32> netsh wlan show all

// All user profile details that are saved or connected //

 

C:\Windows\system32> netsh wlan show profile h04x key=clear     [h04x is my wifi name, put yours]

// All details where In security there are ‘Key Content’ I.e. the password. //

 

 

WIFI HOTSPOT

 

C:\Windows\system32> netsh wlan set hostednetwork mode=allow ssid=LINE key=12345

[ hit enter, where key is the password  // All details shown below // ]

 

C:\Windows\system32> netsh wlan start hostednetwork

// the hosted network started.

// It only works when your PC or Laptop has the ethernet wired connection. This hostpot can be used.

 

C:\Windows\system32>


NETWORKING COMMANDS

Open CMD as administrator.

 

C:\windows\system32> hostname [ system host name]

// hostname show //

 

C:\windows\system32> ipconfig [ IP configuration ]

// details, ISP gateway //

 

C:\windows\system32> getmac [ Mac address ]

//Mac address //

 

C:\windows\system32> ping www.google.com [connection establish checking command]

// Ping details //

 

C:\windows\system32>tracert www.google.com    [ Show Ip from device to google]

// info //

 

C:\windows\system32> netstat

// local and foreign address shown here //

 

C:\windows\system32> nslookup www.google.com   [ ip address finding command ]

// address, name etc. Shown. This address typed on browser and this will redirect on that website. //

 

C:\windows\system32>


CUSTOMIZING TERMINAL

Open CMD as administrator.

 

Right click on the taskbar and go to properties. Set your choice-able color, font, etc.

 

COLOR

 

C:\windows\system32> color 1 [ color number ]

C:\windows\system32> color 2

C:\windows\system32> color 3

// For Color table. Color help will help you.

C:\windows\system32>

 

 

MODE

 

C:\windows\system32> mode 60

C:\windows\system32> mode 120    [ changes it’s size ]

C:\windows\system32> mode 200

 

 

TITLE

 

C:\windows\system32> title TITLEbar [ title bar will shown the name ]

 

 

PROMPT

 

C:\windows\system32> prompt code [‘code’ is now used similar to as command prompt ]

Code ipconfig

// ipconfig details //

Code

 


BEST UTILITY COMMANDS

Open CMD as administrator.

 

C:\windows\system32> tree [ directory wise shown everything ]

// shown tree structure data

 

C:\windows\system32> date

// date set, entered as input and it will shown you in calender *updated.

 

C:\windows\system32> Time

// set time and updated time shown

 

C:\windows\system32> DOSKEY/HISTORY [ All used commands shown here ]

C:\windows\system32> shutdown -s -t 10 [ -r used instead of -s, used for restart. -t is time. 10sec after it will be shutdown ]

C:\windows\system32>

 

 

 

 

 

STAR WAR MOVIE IN CMD

 

Open Control Panel, Go to Programs, Open “Windows features on or off”, There are a dialog box where “Telnet client” option is present, enable this. It takes some time.

 

Now, Open CMD run as administrator mode.

 

C:\windows\system32> telnet towel.blinkenlights.nl. [ after hit entre, some text comes, and then movie starts.

 

 

 

 

BATCH SCRIPTING

How to Create and use batch files?

What are batch files used for?

Basic batch file commands.

 

What is Batch file ?

The definition of a batch file as it used in a Windows/DOS environment is a text file that contains a series of commands that executed in sequence for windows for perform and operation.

 

Why is it called a batch file?

It’s called a batch file  because it “batches” a sequence of commands that would normally have to be ran one at times.

How do you Execute a batch file ?

You can run a batch file two ways. Create a shortcut the batch file or create your own batch file and save it to your desktop or somewhere in the files structure you have access. Then you can either double click the icon for the batch file, or you can execute from the command line simply by typing the filename and extension, e.g. batchfile.bat, and pressing enter.

 

The purpose of batch files is run many DOS commands at once sometimes pausing to allow the administrator to interact with the operation by entering data or starting the process if the process is paused.The Commandsthat are used to program the batch file are similar to DOS commands. Here is a list of the important commands that are used and their definitions:

 

* ECHO -Displays text on the screen.

* ECHO OFF - Hides the text that is normally output.

* START - Run a file with its default application.

* REM - Inserts a comment line in the program.

* MKDIR / RMDIR - Create and remove directories

* DEL - Deletes a file or files

* COPY- Copy a file or files, Allows you to copy files with extra options.

* FOR / IN/ DO - This command lets you specify files.

* TiTLE - Edit the title of the window.

 

Creating your batch file in windows:

 

Once either Notepad or Wordpad is open you can start typing your batch file. Here is an example of a batch file typed out in a text editor. Type the following:

 

@echo off

Echo Hello this is a text file

Pause

Dir c:\windows

Pause

 

Click File and then Save, and then navigate to where you want to save the file. For the file name,  type “test.bat”, and if your version of windows has a “Save as type” option, choose “All files”, otherwise it saves as a text file. Once you have completed these steps, click the save button and exit notepad.

 

To run the batch file, double-click it like any other program. Once the batch file has completed running it closes automatically.

 

Creating the batch file from the Commandline.

1. Open an MS-DOS command window or load MS-DOS.

2. In the MS-DOS prompt, type: edit test.bat and press enter.

3. If typed correctly, you should now see a blue edit screen. Within the screen, type:

@echo  off

Echo Hello this is a text file

Pause

Dir c:\windows

Pause

 

4. Once these three lines are entered, click file and choose exit., when prompted to save, click YES. Users who do not have a mouse cursor can accomplish this same task by pressing ALT + F to access the file menu, and then X to exit. Press Enter to save changes.

5. Once you are back at the MS-DOS prompt, type: test and press enter to execute the test.bat file. Because the first line is a pause, you will first be prompted to press a key. Upon doing so, the batch file runs line-by-line; in this case, listing the files in the Windows and Windows\system directories.

 

 

Here is a batch file for creating and deleting user accounts.

 

ADD USERS

1. Click on Start button

2. At the bottom of start menu in search box type Notepad and press enter key.

3. In the notepad type command NET USER USER1 123 /ADD, where USER1 is the user name that you want to create an 123 is the password for the user account. If you want to create 50 users at a time you can simply copy the entire command and can paste it 50 times on the same notepad and change the user names as per your requirements like USER1, USER2, …and so on.

4. Once you are done with commands you can save the notepad file with .BAT extension. For example, CREATE_USER.BAT . Make sure you specify the file name and extension between “”.

 

 

DELETE USERS

1. Click on start button

2. At the buttom of start menu in search box type notepad and press enter key.

5. In the notepad type command NET USER USER1 123 /DEL,   where USER1 is the user name that you want to create an 123 is the password for the user account. If you want to delete 50 users at a time you can simply copy the entire command and can paste it 50 times on the same notepad and change the user names as per your requirements like USER1, USER2, …and so on.

3. Once you are done with commands you can save the notepad file with .BAT extension. For example, DELETE_USER.BAT . Make sure you specify the file name and extension between “”.

 

 

Open CMD.

Open Notepad.

In notepad, type

Echo Hello

pasue

And save it “batch.bat” type “all types”. and then Save.

 

And run it by clicking it.

If you want to remove the location, type “@echo off”.

@echo off

Echo Hello

pasue

exit /b

This code automatically exit from the terminal by pressing any button.

 

* CLS - clear screen

* pause - hold the terminal

* Echo. - for 1 line space.

* goto label - loop where control jumps on the label (:label ) statement.

 

For Example,

:la1

Echo this is a loop

Goto la1

Exit


 

VARIABLES

 

Within batch program, type this. Where /p is used for input operation. /a means arithmetic operation.

 

Set /p var1=” Enter 1 st number:  “

Set /p var2= “Enter 2 nd number: “

 

Set /a result =  %var1%+%var2%

Echo Your ans is %result%

pause

Save this program and run it.

 

 

DECISION MAKING

 

Open a new file and save it using ‘.bat’ extension.

@echo off

Set  /a var=15

Set /p var2=”Enter a number for matching: “

If %var%==%var2% ( echo Matched! ) Else ( echo Match not found. )

 

Save this program and run it. Try with different values.

 

 

EXAMPLE

1. Random number generator

@echo off

Color 0a

:a

Echo %random% %random%

Goto a

 

 

2. Copy a file in USB

Cd/

Cd users

Cd %username%

Cd desktop

Xcopy M_Virus.bat “E:”

 

Save it and run. Where E drive is the USB drive.

 

3. Delete M_Virus.bat file from USB

Cd/

E:

Del M_virus.bat

 

Save it and run it.

 

4. Text- Image website

Open Text-image website and choose any pic and choose ASCII option to convert.

 

Copy the result and paste it in bat file then go to format and then font “Consolas” style:“Regular” size:“11”. then okay.

 

Type @echo off infront of the bat file

And then set color. At the end, Add pause. Type echo in each line. Save it and run.

 

 

 

 

CONVERT .BAT TO .EXE

 

.exe files are executable files. To convert .bat to .exe file download the following software.

 

Advancedbattoexeconverter.exe from MediaFire website

 

Open this and agree it to install.

 

You can type or import .bat file. And Now Export through these settings,

1. Choose “Windows 2000/xp/win7/win8/win10

2. Choose an icon from “Select icon” option. If you need an icon simply download it from the google (like, JPG to ICO converter).

3. Click on Build EXE. And Save EXE file at your favorite location.

4. Run and Enjoy.


 

NEW GUI COMMAND LINE

If you are bored using normal CMD then Go to your browser and type “PowerCMD”. Enter PowerCMD.com website. Click on Free Download. Install it. After Installation, Open PowerCMD.

A new kind of CMD box appears.

 

C:\program files\PowerCMD> systeminfo

// system  //

C:\program files\PowerCMD> ipconfig

// ip details//

C:\program files\PowerCMD>

 

 

 

 

 

 

Comments

Popular posts from this blog

IMPORTANT INTERVIEW RELATED QUESTION

C++ Interview Questions

SUBLIME TEXT CHEAT SHEET