Visual Basic 2010 Read/Write Command Prompt

Visual Basic Online Course - Command Prompt

Read / Write Windows Command Prompt from VB 2010

Read / Write Windows Command Prompt from Visual Basic 2010

Command Prompt

A command prompt is an entry point for typing computer commands in the Command Prompt window. By typing commands at the command prompt, you can perform tasks on your computer without using the Windows graphical interface.

Command Prompt Commands

(A)
ADDUSERS Add or list users to/from a CSV file
ARP Address Resolution Protocol
~ ASSOC Change file extension associations
ASSOCIAT One step file association
AT Schedule a command to run at a later time
ATTRIB Change file attributes

(B)
BOOTCFG Edit Windows boot settings
BROWSTAT Get domain, browser and PDC info

(C)
CACLS Change file permissions
~ CALL Call one batch program from another
~ CD Change Directory - move to a specific Folder
CHANGE Change Terminal Server Session properties
CHKDSK Check Disk - check and repair disk problems
CHKNTFS Check the NTFS file system
CHOICE Accept keyboard input to a batch file
CIPHER Encrypt or Decrypt files/folders
CleanMgr Automated cleanup of Temp files, recycle bin
CLEARMEM Clear memory leaks
CLIP Copy STDIN to the Windows clipboard.
~ CLS Clear the screen
CLUSTER Windows Clustering
CMD Start a new CMD shell
~ COLOR Change colors of the CMD window
COMP Compare the contents of two files or sets of files
COMPACT Compress files or folders on an NTFS partition
COMPRESS Compress individual files on an NTFS partition
CON2PRT Connect or disconnect a Printer
CONVERT Convert a FAT drive to NTFS.
~ COPY Copy one or more files to another location
CSCcmd Client-side caching (Offline Files)
CSVDE Import or Export Active Directory data

(D)
~ DATE Display or set the date
Dcomcnfg DCOM Configuration Utility
DEFRAG Defragment hard drive
~ DEL Delete one or more files
DELPROF Delete NT user profiles
DELTREE Delete a folder and all subfolders
DevCon Device Manager Command Line Utility
~ DIR Display a list of files and folders
DIRUSE Display disk usage
DISKCOMP Compare the contents of two floppy disks
DISKCOPY Copy the contents of one floppy disk to another
DISKPART Disk Administration
DNSSTAT DNS Statistics
DOSKEY Edit command line, recall commands, and create macros
DSADD Add user (computer, group..) to active directory
DSQUERY List items in active directory
DSMOD Modify user (computer, group..) in active directory

(E)
~ ECHO Display message on screen
~ ENDLOCAL End localisation of environment changes in a batch file
~ ERASE Delete one or more files
~ EXIT Quit the current script/routine and set an errorlevel.
EXPAND Uncompress files
EXTRACT Uncompress CAB files

(F)
FC Compare two files
FIND Search for a text string in a file
FINDSTR Search for strings in files
~ FOR /F Loop command: against a set of files
~ FOR /F Loop command: against the results of another command
~ FOR Loop command: all options Files, Directory, List
FORFILES Batch process multiple files
FORMAT Format a disk
FREEDISK Check free disk space (in bytes)
FSUTIL File and Volume utilities
FTP File Transfer Protocol
~ FTYPE Display or modify file types used in file extension associations

(G)
GLOBAL Display membership of global groups
~ GOTO Direct a batch program to jump to a labelled line

(H)
HELP Online Help 

(I)
~ IF Conditionally perform a command
IFMEMBER Is the current user in an NT Workgroup
IPCONFIG Configure IP

(J)
KILL Remove a program from memory

(L)

LABEL Edit a disk label
LOCAL Display membership of local groups
LOGEVENT Write text to the NT event viewer.
LOGOFF Log a user off
LOGTIME Log the date and time in a file

(M)

MAPISEND Send email from the command line
MBSAcli Baseline Security Analyzer.
MEM Display memory usage
~ MD Create new folders
MKLINK Create a symbolic link (linkd)
MODE Configure a system device
MORE Display output, one screen at a time
MOUNTVOL Manage a volume mount point
~ MOVE Move files from one folder to another
MOVEUSER Move a user from one domain to another
MSG Send a message
MSIEXEC Microsoft Windows Installer
MSINFO Windows NT diagnostics
MSTSC Terminal Server Connection (Remote Desktop Protocol)
MUNGE Find and Replace text within file(s)
MV Copy in-use files

(N)
NET Manage network resources
NETDOM Domain Manager
NETSH Configure network protocols
NETSVC Command-line Service Controller
NBTSTAT Display networking statistics (NetBIOS over TCP/IP)
NETSTAT Display networking statistics (TCP/IP)
NOW Display the current Date and Time
NSLOOKUP Name server lookup
NTBACKUP Backup folders to tape
NTRIGHTS Edit user account rights

(P)
~ PATH Display or set a search path for executable files
PATHPING Trace route plus network latency and packet loss
~ PAUSE Suspend processing of a batch file and display a message
PERMS Show permissions for a user
PERFMON Pe

Example 

1) Copy / Paste filesCopy - This command allows you to copy files from one location to another. To use this command you would type
copy filetocopy copiedfile
For example if you have the file D:\test\test.txt and would like to copy it to c:\windows\test.txt you would type
copy D:\test\test.txt c:\windows\test.txt
and press enter. 
If the copy is successful it will tell you so and give you back the prompt. If you are copying within the same directory you do not have to use the path. 

Here are some examples and what they would do:
copy File.txt ThisFile.bak     Copies the File.txt file to a new file called ThisFile.bak in the same directory
copy File.txt \windows     Copies the File.txt file to the \windows directory.
copy * \windows     Copies all the files in the current directory to the \windows directory.

Redirectors

Re-directors are an important part to using the command prompt as they allow you to manipulate how the output or input of a program is displayed or used. Re-directors are used by appending them to the end of a command followed by what you are redirecting to. For example: Dir > DirOutPuts.txt. There are four re-directors that are used in a command prompt and they are discussed below:

>     This re-director will take the output of a program and store it in a file. If the file exists, it will be overwritten. If it does not exist it will create a new file. For example the command dir > DirOutPuts.txt will take the output of the Dir command and place it in the DirOutPuts.txt file. If dir.txt exists, it will overwrite it, otherwise it will create it.

>>     This re-director will take the output of a program and store it in a file. If the file exists, the data will be appended to the current data in the file rather than overwriting it. If it does not exist it will create a new file. For example the command dir >> dir.txt will take the output of the dir command and appends it to the existing data in the Dir.txt file if the file exists. If dir.txt does not exist, it will create the file first.

<     This re-director will take the input for a program from a specified file. For example the date command expects input from a user. So if we had the command date < date.txt, it would take the input for the date program from the information contained in the date.txt file.

|     This re-director is called a pipe. It will take the output of a program and pipe it into another program. For example Dir | sort would take the output of the dir command and use it as input to the sort command.

How do we use of those info in Visual Basic 2010 ?

There are so many benefits of using Command Prompt Commands in VB 2010, I will give an example of comparing two EXE file (Windows Application) using FC command from VB 2010 which I know is needed most by many developers, there are some tools that actually do that and are based on the usage of FC command.

Example : Compare two applications is called Binary Diff. , FC command operate a comparison process based on the location of the two *.exe files and return the result like this :
xxxxxx: yy zz
The value of xxxxxx specifies the relative hexadecimal address for the pair of bytes, measured from the beginning of the file. Addresses start at 00000000.
The hexadecimal values for yy and zz represent the mismatched bytes from filename1.exe and filename2.exe , respectively.

Syntax :
FC  [drive1:][path1]filename1.exe [drive2:][path2]filename2.exe /B
[drive1:][path1]filename1 : Specifies the location and name of the first file you want to compare. Filename1 is required.
[drive2:][path2]filename2 : Specifies the location and name of the second file you want to compare. Filename2 is required. 
/B  : Compares the files in binary mode. FC compares the two files byte by byte and does not attempt to resynchronize the files after finding a mismatch. This is the default mode for comparing files that have the following file extensions: .exe, .com, .sys, .obj, .lib, or .bin.

To make use of the example :
Create any Visual Basic 2010 Project [Windows Form]
Build it, so you would have an EXE file in Bin\Debug
Copy the exe file to another Dir called C:\Comp, and rename it to (CS.exe)
Edit your Visual Basic 2010 Source Code (Add any line of code)
Build menu : Clear Solution
Build menu : Build solution
now you have another version of the exe file
Rename your recent exe file (Cexe.exe) and paste it in C:\Comp folder with the previous exe file
Now you have 2 different exe (CS.exe and Cexe.exe) files in C:\Comp folder and we want to compare them as Binary Diff.

Create new VB 2010 Project, like this :
VB 2010 Command Prompt
Compare two windows applications in VB 2010 using Command Prompt FC Command
Form
Name : form1
Caption : Compare two exe files
TextBox
'Contains the command Line FC
Name : TextBox1
MultiLine : True
Text :
@Echo Off
FC C:\comp\CS.exe C:\comp\Cexe.exe /B
TextBox
'Will contain the Comparison result of the two EXE application files.
Name
: TextBox2
MultiLine : True
Text :Comparison Result will display here ...
Button
'Executes the Command Line FC in the TextBox1
Name : Button1
Text : Go

Visual Basic Code : Open code area, clear it and paste the following codes ....

Run your application. The result will be like this :
VB 2010 Binary Diff example
Comparison Result of Comparing two windows applications using FC command from VB 2010
You can extend your work further and further ..... If you have any questions please comment. Thank you for reading Visual Basic Online Course - Command Prompt

Here are some online Visual Basic lessons and courses :

Popular posts from this blog

Visual Basic Online Courses DataGridView Add Edit Delete

VB .NET WebView2 WinForms tips

Visual Basic 2010 Working With DataBase Full Project Example

VB NET Check internet connection

Visual Basic .Net - Button Sound / Music Play

Visual Basic 2010 Math Functions