Showing posts with label DOS. Show all posts
Showing posts with label DOS. Show all posts

Tuesday, May 10, 2011

Add or delete or set default printer from DOS

Add or delete or set default printer from DOS

Windows XP provides a VBS script to manage local and network printers from Windows command line. This script is Prnmngr.vbs and can be found in the directory C:\Windows\System32. Using this script, we can add or delete network printers and set or change default printer. Below you can find the syntax and use cases of this script along with some examples.

Add a network printer from windows command line

You can add a network printer by specifying the server name and printer name as in the below command.

cscript C:\windows\system32\prnmngr.vbs -p "printername" -s "servername"

Get the list of printers added to the system from Windows command line(CMD).

cscript C:\windows\system32\prnmngr.vbs -l

Get the default printer details from command line.

cscript C:\windows\system32\prnmngr.vbs -g

Example:

C:\>cscript C:\windows\system32\prnmngr.vbs -g
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

The default printer is \\printer01\LASERJET_8150PRINTER

C:\>

Set default printer from windows command line.

You can run the below command to set default printer.

cscript C:\windows\system32\prnmngr.vbs -t -p "\\Servername\printername"

For example, to set the printer laserjet_02 connected to the server \\printer02 as default, we need to run the below command.

cscript C:\windows\system32\prnmngr.vbs -t -p \\printer02\laserjet_02

Note that double quotes are not required if there is no space in the printer name.

Delete a network printer from windows command prompt:

cscript C:\windows\system32\prnmngr.vbs -d "\\servername\printername"

Wednesday, March 24, 2010

Launching remote desktop from the command line in Windows XP Pro

The Windows XP remote desktop connection dialog box provides you with everything that you need to configure and connect to another computer running Windows XP Pro. You can use the Save As button on the Connection Settings panel to save all your connection settings as an RDP file. Then, you can launch and connect to a remote computer simply by double-clicking the RDP file.

You can also script a remote desktop connection, as Windows XP's remote desktop connection has an executable file that can accept command line parameters and be run from a batch file. The remote desktop connection executable file is MSTSC.EXE, and the following are some of the most common parameters:

  • /v:--specifies the name of the computer to connect to.
  • /f--starts the connection in a full screen.
  • /w:--specifies the width of the remote desktop screen.
  • /h:--specifies the height of the remote desktop screen.

For example, to remotely connect to a computer named Kaltec in a 640 x 480 remote desktop screen, you would use the following command:

mstsc /v: 10.4.45.99 /w:640 /h:480

You can type this command line in the Run dialog box, as well as use it in a batch file.

Note: This tip applies only to Windows XP Professional.

Friday, April 3, 2009

"netstat" - state information on network connections


"netstat" - state information on network connections

The following is sample output using one of the netstat option:
netstat -na|more

Active Connections

Proto Local Address Foreign Address State
TCP 108.168.7.21:139 0.0.0.0:0 LISTENING
TCP 10.17.7.21:1960 20.46.19.9:1863 ESTABLISHED
TCP 10.17.7.21:2971 20.18.11.20:8080 ESTABLISHED
TCP 127.0.0.1:1036 0.0.0.0:0 LISTENING
TCP 127.0.0.1:1110 127.0.0.1:1111 ESTABLISHED
TCP 127.0.0.1:1111 127.0.0.1:1110 ESTABLISHED
TCP 127.0.0.1:1113 127.0.0.1:1114 ESTABLISHED
TCP 127.0.0.1:1114 127.0.0.1:1113 ESTABLISHED
TCP 127.0.0.1:2970 127.0.0.1:30606 ESTABLISHED
TCP 127.0.0.1:5152 0.0.0.0:0 LISTENING
TCP 127.0.0.1:5152 127.0.0.1:1117 CLOSE_WAIT
TCP 127.0.0.1:5354 0.0.0.0:0 LISTENING
TCP 127.0.0.1:30606 0.0.0.0:0 LISTENING
TCP 127.0.0.1:30606 127.0.0.1:2932 TIME_WAIT
TCP 127.0.0.1:30606 127.0.0.1:2936 TIME_WAIT
TCP 127.0.0.1:30606 127.0.0.1:2966 TIME_WAIT
TCP 127.0.0.1:30606 127.0.0.1:2970 ESTABLISHED
TCP 127.0.0.1:62514 0.0.0.0:0 LISTENING



The states are defined as follows:

* CLOSED
Connection is closed.

* LISTEN
Listening for a connection.

* SYN_SENT
Active; sent SYN. Waiting for a matching connection request after having sent a connection request.

* SYN_RCVD
Sent and received SYN. Waiting for a confirming connection request acknowledgment after having both received and sent connection requests.

* ESTABLISHED
Connection established.

* CLOSE_WAIT
Received FIN; waiting to receive CLOSE.

* LAST_ACK
Received FIN and CLOSE; waiting for FIN ACK.

* FIN_WAIT_1
Closed; sent FIN.

* CLOSING
Closed; exchanged FIN; waiting for FIN.

* FIN_WAIT_2
Closed; FIN is acknowledged; awaiting FIN.

* TIME_WAIT
In 2 MSL (twice the maximum segment length) quiet wait after close.

Wednesday, June 11, 2008

DOS - cipher

cipher : Displays or alters the encryption of directories [files] on NTFS partitions.

CIPHER [/E | /D] [/S:directory] [/A] [/I] [/F] [/Q] [/H] [pathname [...]]

CIPHER /K

CIPHER /R:filename

CIPHER /U [/N]

CIPHER /W:directory

CIPHER /X[:efsfile] [filename]

/A Operates on files as well as directories. The encrypted file
could become decrypted when it is modified if the parent
directory is not encrypted. It is recommended that you encrypt
the file and the parent directory.
/D Decrypts the specified directories. Directories will be marked
so that files added afterward will not be encrypted.
/E Encrypts the specified directories. Directories will be marked
so that files added afterward will be encrypted.
/F Forces the encryption operation on all specified objects, even
those which are already encrypted. Already-encrypted objects
are skipped by default.
/H Displays files with the hidden or system attributes. These
files are omitted by default.
/I Continues performing the specified operation even after errors
have occurred. By default, CIPHER stops when an error is
encountered.
/K Creates new file encryption key for the user running CIPHER. If
this option is chosen, all the other options will be ignored.
/N This option only works with /U. This will prevent keys being
updated. This is used to find all the encrypted files on the
local drives.
/Q Reports only the most essential information.
/R Generates an EFS recovery agent key and certificate, then writes
them to a .PFX file (containing certificate and private key) and
a .CER file (containing only the certificate). An administrator
may add the contents of the .CER to the EFS recovery policy to
create the recovery agent for users, and import the .PFX to
recover individual files.
/S Performs the specified operation on directories in the given
directory and all subdirectories.
/U Tries to touch all the encrypted files on local drives. This will
update user's file encryption key or recovery agent's key to the
current ones if they are changed. This option does not work with
other options except /N.
/W Removes data from available unused disk space on the entire
volume. If this option is chosen, all other options are ignored.
The directory specified can be anywhere in a local volume. If it
is a mount point or points to a directory in another volume, the
data on that volume will be removed.
/X Backup EFS certificate and keys into file filename. If efsfile is
provided, the current user's certificate(s) used to encrypt the
file will be backed up. Otherwise, the user's current EFS
certificate and keys will be backed up.


directory A directory path.
filename A filename without extensions.
pathname Specifies a pattern, file or directory.
efsfile An encrypted file path.

Used without parameters, CIPHER displays the encryption state of
the current directory and any files it contains. You may use multiple
directory names and wildcards. You must put spaces between multiple
parameters.

Tuesday, October 2, 2007

DOS - Starts app.

`start` - Starts a separate window to run a specified program or command.
USAGE:
START ["title"] [/Dpath] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/WAIT] [/B] [command/program]
[parameters]

"title" Title to display in window title bar.
path Starting directory
B Start application without creating a new window. The application has ^C handling ignored. Unless the application enables ^C processing, ^Break is the only way to interrupt the application
I The new environment will be the original environment passed to the cmd.exe and not the current environment.
MIN Start window minimized
MAX Start window maximized
SEPARATE Start 16-bit Windows program in separate memory space
SHARED Start 16-bit Windows program in shared memory space
LOW Start application in the IDLE priority class
NORMAL Start application in the NORMAL priority class
HIGH Start application in the HIGH priority class
REALTIME Start application in the REALTIME priority class
ABOVENORMAL Start application in the ABOVENORMAL priority class
BELOWNORMAL Start application in the BELOWNORMAL priority class
WAIT Start application and wait for it to terminate command/program
If it is an internal cmd command or a batch file then the command processor is run with the /K switch to cmd.exe. This means that the window will remain after the command has been run.

If it is not an internal cmd command or batch file then it is a program and will run as either a windowed application or a console application.

parameters These are the parameters passed to the command/program


If Command Extensions are enabled, external command invocation through the command line or the START command changes as follows:

non-executable files may be invoked through their file association just by typing the name of the file as a command. (e.g. WORD.DOC would launch the application associated with the .DOC file extension). See the ASSOC and FTYPE commands for how to create these associations from within a command script.

When executing an application that is a 32-bit GUI application, CMD.EXE does not wait for the application to terminate before returning to the command prompt. This new behavior does NOT occur if executing within a command script.

When executing a command line whose first token is the string "CMD " without an extension or path qualifier, then "CMD" is replaced with the value of the COMSPEC variable. This prevents picking up CMD.EXE from the current directory.

When executing a command line whose first token does NOT contain an extension, then CMD.EXE uses the value of the PATHEXT environment variable to determine which extensions to look for and in what order. The default value for the PATHEXT variable is:

.COM;.EXE;.BAT;.CMD

Notice the syntax is the same as the PATH variable, with semicolons separating the different elements.

When searching for an executable, if there is no match on any extension,then looks to see if the name matches a directory name. If it does, the START command launches the Explorer on that path. If done from the command line, it is the equivalent to doing a CD /D to that path.

EXAMPLE:

C:\>start notepad

Tuesday, August 28, 2007

DOS - `dir`

`dir` - Displays a list of files and subdirectories in a directory.

Usage:
DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[drive:][path][filename]
Specifies drive, directory, and/or files to list.

/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files - Prefix meaning not
/B Uses bare format (no heading information or summary).
/C Display the thousand separator in file sizes. This is the
default. Use /-C to disable display of separator.
/D Same as wide but files are list sorted by column.
/L Uses lowercase.
/N New long list format where filenames are on the far right.
/O List by files in sorted order.
sortorder N By name (alphabetic) S By size (smallest first)
E By extension (alphabetic) D By date/time (oldest first)
G Group directories first - Prefix to reverse order
/P Pauses after each screenful of information.
/Q Display the owner of the file.
/S Displays files in specified directory and all subdirectories.
/T Controls which time field displayed or used for sorting
timefield C Creation
A Last Access
W Last Written
/W Uses wide list format.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name inserted
before the long name. If no short name is present, blanks are
displayed in its place.
/4 Displays four-digit years

Switches may be preset in the DIRCMD environment variable. Override
preset switches by prefixing any switch with - (hyphen)--for example, /-W.

EXAMPLE:

C:\>dir /A
Volume in drive C is SYSTEM
Volume Serial Number is NRF9-8T9A

Directory of C:\

01/12/2007 02:12 PM 332 001.sql
04/26/2006 10:58 AM 0 AUTOEXEC.BAT
08/24/2005 04:18 PM 194 boot.ini
04/26/2005 10:58 AM 0 CONFIG.SYS
07/17/2004 04:03 PM dir Document
04/26/2007 11:03 AM dir Documents and Settings
02/13/2005 01:09 PM 561 INSTALL.LOG
01/26/2007 10:58 AM 0 IO.SYS
01/26/2007 10:58 AM 0 MSDOS.SYS
06/26/2002 02:19 AM 45,124 NTDETECT.COM
06/26/2002 02:19 AM 222,368 ntldr
02/10/2007 09:22 AM 399,491,072 pagefile.sys
04/20/2005 09:09 AM dir Program Files
04/26/2006 12:19 PM dir RECYCLER
02/22/2007 11:03 AM dir System Volume Information
03/23/2007 10:29 AM dir TMP
06/11/1985 05:34 PM 128,000 UNWISE.EXE
06/22/2007 05:55 PM dir WINDOWS
10 File(s) 400,158,372 bytes
8 Dir(s) 24,543,551,488 bytes free

C:\>

DOS - change console foreground and background colors

[WINDOWS XP - DOS]
`color`
- Sets the default console foreground and background colors.

Usage:
COLOR [attr]

attr Specifies color attribute of console output

Color attributes are specified by TWO hex digits -- the first corresponds to the background; the second the foreground.
Each digit can be any of the following values:

0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White

If no argument is given, this command restores the color to what it was
when CMD.EXE started. This value either comes from the current console
window, the /T command line switch or from the DefaultColor registry
value.

The COLOR command sets ERRORLEVEL to 1 if an attempt is made to execute
the COLOR command with a foreground and background color that are the
same.

Example:

"COLOR fc" produces light red on bright white
C:\>color fc



Monday, August 27, 2007

DOS - `vol`

`vol` - Displays the disk volume label and serial number, if they exist.

Usage:
VOL [drive:]

Example:

C:\>vol
Volume in drive C is SYSTEM
Volume Serial Number is PCD4-4R59

Thursday, August 23, 2007

DOS - `SYSTEMINFO`

`SYSTEMINFO` [/S system [/U username [/P [password]]]] [/FO format] [/NH]

Description:
This command line tool enables an administrator to query for basic
system configuration information.

Parameter List:
/S system Specifies the remote system to connect to.

/U [domain\]user Specifies the user context under which
the command should execute.

/P [password] Specifies the password for the given
user context. Prompts for input if omitted.

/FO format Specifies the format in which the output
is to be displayed.
Valid values: "TABLE", "LIST", "CSV".

/NH Specifies that the "Column Header" should
not be displayed in the output.
Valid only for "TABLE" and "CSV" formats.

/? Displays this help/usage.

Examples:
SYSTEMINFO
SYSTEMINFO /?
SYSTEMINFO /S system
SYSTEMINFO /S system /U user
SYSTEMINFO /S system /U domain\user /P password /FO TABLE
SYSTEMINFO /S system /FO LIST
SYSTEMINFO /S system /FO CSV /NH

C:\>systeminfo
Host Name: XXXXXXXXXXXXXXX

Name: Microsoft Windows XP ProfessionalOS
Version: X.X.2X00 Build 2XX0OS
Manufacturer: Microsoft CorporationOS
Configuration: Standalone WorkstationOS Build
Type: XXXXXXXXXXXXXXXXX
Owner: XXXXXXXXXXx
Registered Organization: XXXXXx
Product ID: XXXXX-XVM-0XXX1G3-0GHN2
Original Install Date: 1/26/2000, 11:02:06 AM
System Up Time: 100 Days, 1 Hours, 55 Minutes, 59 Seconds
System Manufacturer: XXXXXXXXXXXXXXXx
System Model: XXXXXXXXXXX
System type: X86-based PC
Processor(s): 12 Processor(s) Installed.
[01]: XXXXXXXXXXXXXXXXXXXXXXXXXX
BIOS Version: XXXX - 6
Windows Directory: C:\WINDOWS
System Directory: C:\WINDOWS\System32
Boot Device: \Device\HarddiskVolume1
.................
....

Friday, August 17, 2007

DOS - `bootcfg`

`bootcfg`
This command line tool can be used to configure, query, change or delete the boot entry settings in the BOOT.INI file.

Usage:
BOOTCFG /parameter [arguments]

Parameter List:
/Copy Makes a copy of an existing boot entry [operating systems] section for which you can add OS options to.
/Delete Deletes an existing boot entry in the [operating systems] section of the BOOT.INI file. You must specify the entry# to delete.
/Query Displays the current boot entries and their settings.
/Raw Allows the user to specify any switch options to be added for a specified boot entry.
/Timeout Allows the user to change the Timeout value.
/Default Allows the user to change the Default boot entry.
/EMS Allows the user to configure the /redirect switch for headless support for a boot entry.
/Debug Allows the user to specify the port and baudrate for remote debugging for a specified boot entry.
/Addsw Allows the user to add predefined switches for a specific boot entry.
/Rmsw Allows the user to remove predefined switches for a specific boot entry.
/Dbg1394 Allows the user to configure 1394 port debugging for a specified boot entry.
/? Displays this help/usage.


Examples:

BOOTCFG /Copy /?
BOOTCFG /Delete /?
BOOTCFG /Query /?
BOOTCFG /Raw /?
BOOTCFG /Timeout /?
BOOTCFG /EMS /?
BOOTCFG /Debug /?
BOOTCFG /Addsw /?
BOOTCFG /Rmsw /?
BOOTCFG /Dbg1394 /?
BOOTCFG /Default /?
BOOTCFG /?

C:\>bootcfg
Boot Loader Settings

--------------------
timeout: 30
default: multi(0)disk(0)rdisk(0)partition(1)\WINDOWS

Boot Entries
------------
Boot entry ID: 1
Friendly Name: "Microsoft Windows XP Professional"
Path: multi(0)disk(0)rdisk(0)partition(1)\WINDOWSOS Load Options: /fastdetect

DOS - `CD`

`CD` - Displays the name of or changes the current directory.

EXALPLE:

C:\>cd
C:\

.......

C:\>cd WINDOWS
C:\WINDOWS>

C:\WINDOWS>cd ..
C:\>



.....

DOS - `LABEL`

`LABEL` - Creates, changes, or deletes the volume label of a disk.

EXAMPLE:

C:\>label
Volume in drive C: is SYSTEM
Volume Serial Number is RHF4-4T59
Volume label (ENTER for none)?
Delete current volume label (Y/N)? n



DOS-Defragment disk


`defrag` - Windows Disk Defragmenter

Usage:
defrag [-a] [-f] [-v] [-?]
volume drive letter or mount point (d: or d:\vol\mountpoint)
-a Analyze only
-f Force defragmentation even if free space is low
-v Verbose output
-? Display this help text


EXAMPLE:

C:\>defrag c:
Windows Disk Defragmenter
Copyright (c) 2003 Microsoft Corp. and Executive Software International, Inc.
Analysis Report 16.00 GB Total, 8.11 GB (50%) Free, 9% Fragmented (17% file fragmentation)Defragmentation Report 16.00 GB Total, 8.11 GB (50%) Free, 9% Fragmented (16% file fragmentation)

C:\>defrag -a c:
Windows Disk Defragmenter
Copyright (c) 2001 Microsoft Corp. and Executive Software International, Inc.
Analysis Report

37.24 GB Total, 9.70 GB (26%) Free, 8% Fragmented (15% file fragmentation)

Thursday, August 9, 2007

DOS - ipconfig

USAGE: ipconfig [/? /all /renew [adapter] /release [adapter]
/flushdns /displaydns /registerdns
/showclassid adapter
/setclassid adapter [classid] ]

Options:
/? Display this help message
/all Display full configuration information.
/release Release the IP address for the specified adapter.
/renew Renew the IP address for the specified adapter.
/flushdns Purges the DNS Resolver cache.
/registerdns Refreshes all DHCP leases and re-registers DNS names
/displaydns Display the contents of the DNS Resolver Cache.
/showclassid Displays all the dhcp class IDs allowed for adapter.
/setclassid Modifies the dhcp class id.
The default is to display only the IP address, subnet mask anddefault gateway for each adapter bound to TCP/IP.
For Release and Renew, if no adapter name is specified, then the IP addressleases for all adapters bound to TCP/IP will be released or renewed.
For Setclassid, if no ClassId is specified, then the ClassId is removed.

Examples:
> ipconfig /all ... Show detailed information
Windows IP Configuration
Host Name . . . . . . . . . . . . : Sample Machine

Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : Yes
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :

Description . . . . . . . . . . . : Intel(R) PRO/1000 MT Network Connection
Physical Address. . . . . . . . . : B9-09-99-99-99-1A
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 1.24.196.102
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 1.24.196.71
DNS Servers . . . . . . . . . . . : 1.24.196.9

-----------------------------------
> ipconfig /release *Con* ... release all matching connections,
Windows IP Configuration
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :

IP Address. . . . . . . . . . . . : 0.0.0.0
Subnet Mask . . . . . . . . . . . : 0.0.0.0
Default Gateway . . . . . . . . . : 0.0.0.0
-------------------------------------
> ipconfig /renew ... renew all adapters
> ipconfig /renew EL* ... renew any connection that has its name starting with EL