Treasure Of Tips

WIN XP,WIN 7,MOBILE SECRET CODES &TIPS, BLOGGING,PHOTOSHOP,&MANY MORE TIPS&TRICKS DAILY VISIT SITE FOR MORE TREASURE

New Posts

Search This Blog

Monday, January 30, 2012

Dos Syntax 3

To Know The Contents And Purpose Of This BLOG Go To ABOUT Page !

DOS COMMANDS SYNTAX 3, TREASURE--> DOWNLOAD
41). DIRUSE = Display disk usage...
(EXPLAIN - DIRUSE)
Display disk usage

Syntax
DIRUSE [options] Folders...

Options
/M Display in Mb
/K Display in Kb
/B Display in bytes (default)
/, Use thousand separator when displaying sizes.
/Q:# Quota limit, mark folders that exceed the size (#) with a "!".
set %errorlevel% to ONE if any folders are found that
exceed the specified size

/* Report on one level of subfolders (top-level folders)

/D Display only folders that exceed specified sizes.
/S Include detail of every subfolder in the output
/O Don't check subfolders for quota overflow.
/V Display progress report for every subfolder

/C Use Compressed size instead of apparent size.
/L Output overflows to logfile .\DIRUSE.LOG.
/A generate an alert if quota is exceeded
(requires the Alerter service)

Note: the '-' symbol can be used in place of the '/' symbol.

Example

DIRUSE /M /q:1.5 /* e:\users
Please Leave Your Comment

42). DISKCOMP = Compare the contents of two floppy disks...
(EXPLAIN - DISKCOMP)
Compare the content of two floppy disks.

Syntax
DISKCOMP floppy_drive1: floppy_drive2:

Key
floppy_drive is the drive letter

The two disks must be the same type,
e.g. both 1.44 Mb or both 720 K

If you specify the same drive letter for floppy_drive1 and floppy_drive2 - you will be prompted to enter each disk.

For Example:

DISKCOMP A: A:
Please Leave Your Comment

43). DISKCOPY = Copy the contents of one floppy disk to another...
(EXPLAIN - DISKCOPY.com)
Copy the content of one floppy disk to another.

Syntax
DISKCOPY flopppy_drive1: floppy_drive2: [/V]

Key
/V Verify that the information was copied correctly.

The two disks must be the same type,
e.g. both 1.44 Mb or both 720 K

If you specify the same drive letter for floppy_drive1 and floppy_drive2 - you will be prompted to enter each disk.
DISKCOMP A: A:
Please Leave Your Comment

44). DISKPART = Disk Administration...
(EXPLAIN - DiskPart (Windows 7)
Disk Administration, Partition a disk. This page documents the Windows 7/2008 version of Diskpart, an earlier version of Diskpart is supplied in the 2003 Resource kit with a reduced set of options.

Syntax
DISKPART

Commands you may then issue at the DISKPART prompt:

LIST Disk
LIST Partition
LIST Volume

SELECT Disk=n
SELECT Partition=n
SELECT Volume=n_or_d (Number or Drive Letter)

DETAIL Disk
DETAIL Partition
DETAIL volume

ACTIVE (set the current in-focus partition to be the system partition)
ASSIGN (allocate the next free drive letter)
ASSIGN LETTER=E (Choose a free letter)
ATTRIBUTES DISK [{set | clear}] [readonly] [noerr]
ATTRIBUTES VOLUME [{set | clear}] [{hidden | readonly | nodefaultdriveletter | shadowcopy}] [noerr]
AUTOMOUNT [enable] [disable] [scrub] [noerr]
FILESYSTEMS (Use 'Select Volume' first)
HELP
INACTIVE (mark a system/boot partition as inactive [don't boot], use 'Select Partition' first)
OFFLINE disk [noerr] (Take the current disc offline, use 'Select Disk' first)
ONLINE {disk|volume} [noerr]
REM (remark/comment)
REMOVE letter=E [dismount] [noerr] (Remove drive letter E from the in-focus partition)
REMOVE mount=path [dismount] [noerr] (Remove mount point from the in-focus partition)
REMOVE /ALL [dismount] [noerr] (Remove ALL current drive letters and mount points)
RESCAN (Locate new disks that have been added to the computer)
SHRINK [desired=n] [minimum=n] [nowait] [noerr] (Reduce the size of the in-focus volume)
SHRINK querymax [noerr]
EXIT
UNIQUEID disk [id={dword | GUID}] [noerr] (Display or set the GUID partition table identifier
or MBR signature for the disk with focus)

Commands to Manage Basic Disks:

ASSIGN MOUNT=path (Choose a mount point path for the volume)

CREATE PARTITION Primary Size=50000 (50 GB)
CREATE PARTITION Extended Size=25000
CREATE PARTITION logical Size=25000
DELETE Partition
EXTEND Size=10000
GPT attributes=n (assign GUID Partition Table attributes)
SET id=byte|GUID [override] [noerr] (Change the partition type)

Commands to Manage Dynamic Disks:

ADD disk=n (Add a mirror to the in-focus SIMPLE volume on the specified disk
see 'Diskpart Help' for more.)
BREAK disk=n (Break the current in-focus mirror)
CREATE VOLUME Simple Size=n Disk=n
CREATE VOLUME Stripe Size=n Disk=n,n,...
CREATE VOLUME Raid Size=n Disk=n,n,...
DELETE DISK
DELETE PARTITION
DELETE VOLUME
EXTEND Disk=n [Size=n]
EXTEND Filesystem [noerr]
IMPORT [noerr] (Import a foreign disk group, use 'Select Disc' first)
RECOVER [noerr] (Refresh disc pack state, attempt recovery on an invalid pack,
& resynchronize stale plex/parity data.)
REPAIR disk=n [align=n] [noerr] (Repair the RAID-5 volume with focus, replace with the specified dynamic disk)
RETAIN (Prepare an existing dynamic simple volume to be used as a boot or system volume)

Commands to Convert Disks

CONVERT basic
CONVERT dynamic
CONVERT gpt
CONVERT mbr
CLEAN [ALL] (remove all partition and volume info from the hard drive)
FORMAT [{fs=ntfs|fat|fat32] [revision=x.xx] | recommended}]
[label="label"] [unit=n] [quick] [compress]
[override] [nowait] [noerr]

The diskpart commands may be placed in a text file (one command per line) and used as an input file to diskpart.exe:

DiskPart.exe < myscript.txt Example: SELECT DISK=0 CREATE PARTITION PRIMARY ASSIGN LETTER=E SELECT PARTITION=1 FORMAT FS=NTFS LABEL="New Volume" QUICK EXIT noerr - This option is for scripting only. With noerr set, when an error is encountered, DiskPart will continue to process commands as if the error did not occur. Without this parameter, an error causes DiskPart to exit with an error code. When selecting a volume or partition, you may use either the number or drive letter or the mount point path. Always back up the hard disk before running diskpart.
Please Leave Your Comment

45). DNSSTAT = DNS Statistics...
(EXPLAIN - DNSSTAT)
Please Leave Your Comment

46). DOSKEY = Edit command line, recall commands, and create macros...
(EXPLAIN - DOSKEY.exe)
Recall and edit commands at the DOS prompt, and create macros. You cannot run a Doskey macro from a batch file.

Syntax
DOSKEY [options] [macroname=[text]]

Key
macroname : A short name for the macro.

text : The commands you want to recall.

options : for working with macros...

/MACROFILE=filename Specify a file of macros to install

/MACROS Display all Doskey macros

/EXENAME=exename Specify an executable other than cmd.exe

/MACROS:exename Display all Doskey macros for the given executable

/MACROS:ALL Display all Doskey macros for all executables

ALT+F10 Clear macro definitions

options : for working with the Command Buffer...

/HISTORY : Display all commands stored in memory.
/LISTSIZE=size : Limit the number of commands remembered by the buffer.
/REINSTALL : Install a new copy of Doskey (clears the buffer).

In normal use the command line is always in overwrite mode, DOSKEY can be used to
change this to Insert, the insert key will always toggle from one to the other

/INSERT : By default new text you type at the command line
will be inserted in old text

/OVERSTRIKE : By default new text you type at the command line
will overwrite old

In addition to the above, DOSKEY is loaded into memory for every cmd session so you can use Keyboard shortcuts at the command line

The size of the command history can be set from Control Panel, Console or from the properties of any cmd shortcut. Clear all history with DOSKEY /REINSTALL

Examples:
A macro to open notepad
DOSKEY note=notepad.exe

A macro to open WordPad
DOSKEY wpad="C:\Program Files\Windows NT\Accessories\wordpad.exe"

A macro called `d' to run dir/w
DOSKEY d=dir/w

A macro to disable the FORMAT command
DOSKEY FORMAT=;Ive disabled the Format command

More advanced macro definitions:

$T If you put more than one command in a DOSKEY macro, use $T.
to separate them. Equivalent to & in a batch file.

$1-$9 Parameters, equivalent to %1-%9 in a batch file.

$* This represents ALL the parameters $1-9

A macro to open a file with WordPad:
DOSKEY wpad="C:\Program Files\Windows NT\Accessories\wordpad.exe" $1
Using the above macro:
>wpad MyTextfile.txt

Save and restore macro definitions

DOSKEY macros are only saved for the current session.
The command:
doskey /macros >macros.cmd
Will list all current macro definitions into macros.cmd, edit this file and place DOSKEY at the start of each line. Then to restore all the doskey macros setup in the current session at a later date, just run ' macros.cmd'.
Please Leave Your Comment

47). DSACLs = Active Directory ACLs...
(EXPLAIN - DSACLS.exe)
View or Edit ACLs (access control entries) for objects in Active Directory.

Syntax
DSACLS "[\\Computer\]ObjectDN" [/A] [/D PermissionStatement [PermissionStatement]...]
[/G PermissionStatement [PermissionStatement]...] [/I:{T | S | P}]
[/N] [/P:{Y | N}]
[/R {User | Group} [{User | Group}]...] [/S [/T]]

PermissionStatements:
{User | Group}:Permissions[;{ObjectType | Property}][;InheritedObjectType]

Key
ObjectDN Distinguished name of the object.
If omitted will be taken from standard input (stdin)

/A Add ownership and auditing information to the results.

/D Deny permissions to a user or group

/G Grant permissions to a user or group.

/I: Inheritance
T The object and its child objects (default)
S The child objects only
P The object and child objects down one level only

/N Replace the current ACEs in the ACL.
By default, dsacls adds the ACE to the ACL.

/P: Inherit permissions from parent objects (Y/N).

/R Revoke/Delete all ACEs for the users or groups.

/S Restore the default security.
Default security for each object class is defined in the Active Directory schema.

/S /T Restore the default security on the tree of objects.

Permissions
GR: Generic Read
GE: Generic Execute
GW: Generic Write
GA: Generic All

SD: Delete an object
DT: Delete an object and all of its child objects
RC: Read security information
WD: Change security information
WO: Change owner information
LC: List the child objects of the object
CC: Create a child object•
DC: Delete a child object•
WS: Write to a self object (group membership) group object + {ObjectType | Property} = "member."
RP: Read a property•
WP: Write to a property•
CA: Control access (normally a specific extended right for control access)
If you do not specify {ObjectType | Property} this permission will apply to all
meaningful control accesses on the object.
LO: List the object access, AD DS does not enforce this permission by default.
Grant list access to a specific object when List Children (LC) is not granted to the parent.
Deny list access to a specific object when the user or group has LC permission on the parent.

ObjectType | Property
Limit the permission to the specified object type or property.
Enter the display name of the object type or the property.
Default=all object types and properties.

For example, Grant the user rights to create all types of child objects:
/G Domain\User:CC

Grant the user rights to create only child computer objects:
/G Domain\User:CC;computer

InheritedObjectType
Limit inheritance of the permission to the specified object type.
For example, Grant only User objects to inherit the permission:
/G Domain\User:CC;;user

Object Types
User,Contact,Group,Shared Folder,Printer,Computer,Domain Controllers,OU

• If you do not specify {ObjectType | Property} to define a specific child object type, this permission applies to all types of child objects; otherwise, it applies only to the child object type that you specify.

You can Grant, Deny or Delete ACEs for multiple users and groups with a single parameter (/G /D /R), list the users/groups separated with spaces.

DS* commands are available on networked machines with the server role A.D. Domain Services installed, Domain Controllers (or for XP users: XP Professional).

Examples

Grant Generic Read (GR) and Generic Execute (GE) on computer objects in the Laptops OU to Jdoe:

C:\> dsAcls "OU=Laptops,OU=AcmeCo,DC=ss64,DC=Com" /G Domain\JDoe:GRGE;computer
Please Leave Your Comment

48). DSAdd = Add items to active directory...
(EXPLAIN - DSADD.exe)
Add active directory object.

Syntax
DSADD Computer
DSADD Contact
DSADD Group
DSADD OU
DSADD User
DSADD Quota

DS* commands are available on networked machines with the server role A.D. Domain Services installed, Domain Controllers (or for XP users: XP Professional).

Special characters in distinguished names

Commas within a CN must be escaped with the backslash \ character
e.g. "CN=Company\, Inc.,CN=Users,DC=ss64,DC=com"

Backslashes must also be escaped with a backslash
for example, "CN=Sales\\ Latin America,OU=Distribution Lists,DC=ss64,DC=com"

If any value contains spaces, use quotation marks:
e.g. "CN=John Smith,CN=Users,DC=SS64,DC=com"

Redirection
You can pipe results from DSQUERY into DSMOD in order to modify an object. If the DN contains any commas or backslashes you will need to redirect to a file first and add the escape characters as above.

Special Tokens
The token $username$ (case insensitive) may be used to place the SAM account name.
Entering * as a password will cause DSADD to prompt for the new password.

Adding multiple Objects
For any DS command you can enter multiple values separated by spaces.
e.g. to add several user accounts at once just supply a list of the distinguished names separated with spaces.
It is also possible to store multiple values in a text file and redirect into DSADD.
How to Organize Active Directory

This is a common question, so below is an example starting point, this assumes a domain name of SS64.com, obviously customise that to your own domain.

Placing everything under a single OU, (in this case ACMECo) makes it easy to apply group policy to everything, though in almost all cases you would do this one level down - applying policy to all users or all workstations. Separate OUs are setup for Users, Groups, Servers, Workstations and the IT department (Admin).

AcmeCo
AcmeCo/Admin (OU=Admin,OU=AcmeCo,DC=ss64,DC=com)
AcmeCo/Groups (OU=Groups,OU=AcmeCo,DC=ss64,DC=com)
AcmeCo/Users (OU=Users,OU=AcmeCo,DC=ss64,DC=com)
AcmeCo/Servers (OU=Servers,OU=AcmeCo,DC=ss64,DC=com)
AcmeCo/Laptops (OU=Laptops,OU=AcmeCo,DC=ss64,DC=com)
AcmeCo/Workstations (OU=Workstations,OU=AcmeCo,DC=ss64,DC=com)
AcmeCo/Workstations/Site1
AcmeCo/Workstations/Site2
AcmeCo/Workstations/Site3

PartnerCo An OU for external contacts
PartnerCo/Users (OU=Users,OU=PartnerCo,DC=ss64,DC=com)
PartnerCo/Workstations (OU=Workstations,OU=PartnerCo,DC=ss64,DC=com)

If possible store all USER accounts in a single OU. Organisations change and people move around, there is rarely any reason to reflect every such change in Active Directory. One reason for adding additional USER OUs is to allow delegated rights i.e. to allow super users to do password resets.

The default (built in) Organizational Units (OUs) for Users (CN=Computers,DC=ss64,DC=com) and Computers (CN=Users,DC=ss64,DC=com) will often be used by application installers when creating service accounts.
Please Leave Your Comment

49). DSGet = View items in active directory...
(EXPLAIN - DSGET.exe)
View active directory objects.

Syntax
DSGet Computer
DSGet Contact
DSGet Group
DSGet OU
DSGet Partition
DSGet Quota
DSGet Server
DSGet Subnet
DSGet User

DS* commands are available on networked machines with the server role A.D. Domain Services installed, Domain Controllers (or for XP users: XP Professional).

Special characters in distinguished names

Commas within a CN must be escaped with the backslash \ character
e.g. "CN=Company\, Inc.,CN=Users,DC=ss64,DC=com"

Backslashes must also be escaped with a backslash
for example, "CN=Sales\\ Latin America,OU=Distribution Lists,DC=ss64,DC=com"

If any value contains spaces, use quotation marks:
e.g. "CN=John Smith,CN=Users,DC=SS64,DC=com"

Redirection
You can pipe results from DSQUERY into DSGet in order to view multiple objects. If the DN contains any commas or backslashes you will need to redirect to a file first and add the escape characters as above.

Special Tokens
The token $username$ (case insensitive) may be used to place the SAM account name.
Entering * as a password will cause DSMOD to prompt for the new password.

For any DS command you can enter multiple values separated by spaces.
e.g. to modify several user accounts at once just supply a list of the distinguished names separated with spaces.
Please Leave Your Comment

50). DSQuery = Search for items in active directory...
(EXPLAIN - DSQUERY)
Search for an active directory object.

Syntax
DSQuery Computer
DSQuery Contact
DSQuery Group
DSQuery OU
DSQuery Site
DSQuery Server
DSQuery User
DSQuery Quota
DSQuery Partition
DSQuery * (LDAP query)

DS* commands are available on networked machines with the server role A.D. Domain Services installed, Domain Controllers (or for XP users: XP Professional).

Commas within a CN must be escaped with the backslash \ character CN=Company\, Incorporated...

Escape Backslashes with a second backslash CN=Sales\\ Latin America...

If any value contains spaces, use quotation marks: "CN=John Smith,CN=Users,DC=SS64,DC=com"

Special Tokens
The token $username$ (case insensitive) may be used to place the SAM account name.
Entering * as a password will prompt for a new password.

Adding multiple Objects
For any DS command you can enter multiple values separated by spaces.
e.g. to add several user accounts at once just supply a list of the distinguished names separated with spaces.

It is also possible to store multiple values in a text file and redirect into DSQUERY.

Powershell
To call dsquery and store the resulting string in a powershell array variable (from PowershellHell):
$arrComputerList = $(&dsquery computer -limit 0)|%{$_.Split("=")[1].replace(",OU","").replace(",CN","")}
Please Leave Your Comment

51). DSMod = Modify items in active directory...
(EXPLAIN - DSMOD.exe)
Modify active directory object.

Syntax
DSMOD Computer
DSMOD Contact
DSMOD Group
DSMOD OU
DSMOD Server
DSMOD User
DSMOD Quota
DSMOD Partition

DS* commands are available on networked machines with the server role A.D. Domain Services installed, Domain Controllers (or for XP users: XP Professional).

Special characters in distinguished names

Commas within a CN must be escaped with the backslash \ character
e.g. "CN=Company\, Inc.,CN=Users,DC=ss64,DC=com"

Backslashes must also be escaped with a backslash
for example, "CN=Sales\\ Latin America,OU=Distribution Lists,DC=ss64,DC=com"

If any value contains spaces, use quotation marks:
e.g. "CN=John Smith,CN=Users,DC=SS64,DC=com"

Redirection
You can pipe results from DSQUERY into DSMOD in order to modify an object. If the DN contains any commas or backslashes you will need to redirect to a file first and add the escape characters as above.

e.g. To find all users in the Marketing OU (organizational unit) and add them to the Sales group:

DSQUERY user -startnode "ou=Marketing,dc=SS64,dc=com" | DSMOD group "cn=Sales,ou=Marketing,dc=SS64,dc=com" -addmbr

Special Tokens
The token $username$ (case insensitive) may be used to place the SAM account name.
Entering * as a password will cause DSMOD to prompt for the new password.

For any DS command you can enter multiple values separated by spaces.
e.g. to modify several user accounts at once just supply a list of the distinguished names separated with spaces.
Please Leave Your Comment

52). DSMove = Move an Active directory Object...
(EXPLAIN - DSMOVE.exe)
Rename or Move an active directory object (user, computer, group..) to a different Organisational Unit (OU).

Syntax
dsmove ObjectDN [-newname NewRDN] [-newparent ParentDN]
[{-s Server | -d Domain}]
[-u UserName] [-p {Password | *}]
[-q] [{-uc | -uco | -uci}]

Options
ObjectDN Distinguished name of the computer that you want to add.
If omitted will be taken from standard input (stdin)

-newname Rename the object with a new Relative Distinguished Name.

-newparent New location for the object, enter the new parent DN.

-q Quiet, suppress all output

-uc Unicode format
-uco Unicode format for output only
-uci Unicode format for input only

-u UserName The user name with which a user logs on to a remote server.
By default, the currently logged on user.

-p Password The password, or * to prompt for a password.

By default, DSMOVE connects the computer to the domain controller in the logon domain.

DS* commands are available on networked machines with the server role A.D. Domain Services installed, Domain Controllers (or for XP users: XP Professional).

For any DS command you can enter multiple values separated by spaces.
e.g. to modify several user accounts at once just supply a list of the distinguished names separated with spaces.

Examples

Rename a user:

C:\> set _andy="CN=Andrew Gorden,OU=Europe,DC=ss64,DC=Com"
C:\> dsmove %_andy% -newname "Andrew Gordon"

Move a user to a different OU

C:\> set _andy="CN=Andrew Gordon,OU=Europe,DC=ss64,DC=Com"
C:\> set _newOrgUnit="OU=Asia,DC=ss64,DC=Com"
C:\> dsmove %_andy% -newparent %_newOrgUnit%
Please Leave Your Comment

53). DSRM = Remove items from Active Directory...
(EXPLAIN - DSRM)
Delete objects from active directory.

Syntax
DSRM ObjectDN [-subtree [-exclude]] [-noprompt]
[{-s Server | -d Domain}] [-u UserName] [-p {Password | *}]
[-c] [-q] [{-uc | -uco | -uci}]

Key
ObjectDN Distinguished name of the group that you want to remove.
If omitted will be taken from standard input (stdin)

-subtree Delete the object and all objects contained in its subtree.
-exclude Delete all objects contained in the subtree, but not the object itself.

-noprompt Do not prompt to confirm deletion.

-s Server Connect to a remote server/domain, default=%logonserver% domain controller.

-c Continue with the next object after any error (when you specify multiple target objects)
by default dsrm will exit when the first error occurs.

-q Quiet, suppress all output

-uc Unicode format
-uco Unicode format for output only
-uci Unicode format for input only

DS* commands are available on networked machines with the server role A.D. Domain Services installed, Domain Controllers (or for XP users: XP Professional).

Examples

Remove all objects under the OU AcmeCo, but leave the OU intact:

C:\> dsrm -subtree -exclude -noprompt -c "OU=AcmeCo,DC=ss64,DC=Com"

Find all computers that have been inactive for the last eight weeks and remove them:

C:\> dsquery computer -inactive 8 | dsrm
Please Leave Your Comment








54). ECHO = Display message on screen...
EXPLAIN - ECHO)
Display messages on screen, turn command-echoing on or off.

Syntax
ECHO [ON | OFF]
ECHO [message]
Key
ON : Display each line of the batch on screen (default)
OFF : Only display the command output on screen
message : a string of characters to display

Type ECHO without parameters to display the current echo setting (ON or OFF).

In most batch files you will want ECHO OFF, turning it ON can be useful when debugging a problematic batch script.

In a batch file, the @ symbol is the same as ECHO OFF applied to the current line only.

Normally a command is executed and takes effect from the next line onwards, @ is a rare example of a command that takes effect immediately.

Command characters will normally take precedence over the ECHO statement
e.g. The redirection and pipe characters: & < > | ON OFF

To override this behaviour you can escape each command character with ^ as follows:

ECHO Nice ^&Easy
ECHO Salary is ^> Commision
ECHO Name ^| Username ^| Expiry Date
ECHO:Off On Holiday

Echo text into a FILE

The general syntax is
Echo This is some Text > FileName.txt

or if you want to avoid extra spaces:
Echo Some more text>FileName.txt

Echo a Variable

To display a department variable:

ECHO %_department%

An alternative is to separate with : instead of a space, this has some performance benefits.

ECHO:%_department%

If the variable does not exist - ECHO will simply return the text "%_department%"

This can be extended to search and replace parts of a variable or display substrings of a variable.

Echo a file

see the TYPE command for this

Echo a sound

The following command in a batch file will trigger the default beep on most PC's

ECHO

Use Ctrl-G (or 'Alt' key, and 7 on the numeric keypad) to get this character (ascii 7)

Alternatively using Sound Recorder or Media Player:

START/min sndrec32 /play /close %windir%\media\ding.wav

START/min mplay32 /play /close %windir%\media\ding.wav

Echo a blank line

The following command in a batch file will produce an empty line

ECHO.

To ECHO text without including a CRLF see this discussion

Echo text into a stream

Streams allow one file to contain several separate forks of information (like the macintosh resource fork)

The general syntax is

Echo Text_String > FileName:StreamName

Only the following commands support the File:Stream syntax - ECHO, MORE, FOR

Creating streams:

Echo This is stream1 > myfile.dat:stream1
Echo This is stream2 > myfile.dat:stream2

Displaying streams:

More < myfile.dat:stream1 More < myfile.dat:stream2 FOR /f "delims=*" %%G in (myfile.dat:stream1) DO echo %%G FOR /f "delims=*" %%G in (myfile.dat:stream2) DO echo %%G A data stream file can be successfully copied and renamed despite the fact that most applications and commands will report a zero length file. The file size can be calculated from remaining free space. The file must always reside on an NTFS volume.
Please Leave Your Comment

55). ENDLOCAL = End localisation of environment changes in a batch file...
(EXPLAIN - ENDLOCAL)
End localisation of environment changes in a batch file. Pass variables from one batch file to another.

Syntax
ENDLOCAL

If SETLOCAL is used to make variables 'local' to one batch script, then those variables will be invisible to all other batch scripts unless explicitly passed using an ENDLOCAL & SET... command.

If SETLOCAL is used without a corresponding ENDLOCAL then local environment variables will be discarded when the batch file ends. Ending the cmd.exe session will discard all Environment Variables both local and global.

Passing variables from one routine to another

The CMD command processor always works on a line-by-line basis, so it will convert all %variables% into their text values before executing any of the commands.

By putting ENDLOCAL & SET commands on a single line you are able to SET a variable just before the localisation is ended by the ENDLOCAL command.


Examples:

::Sales.cmd

@Echo off
SETLOCAL
Set _item="Ice Cream Maker"
Set _price=450
ENDLOCAL & SET _return1=%_item%& SET _return2=%_price%

::Results.cmd

@Echo off
SETLOCAL
CALL Sales.cmd
Echo [%_return1%] will cost [%_return2%]


::SubDemo.cmd

@Echo off
SETLOCAL
CALL sub_products
Echo [%_return1%] will cost [%_return2%]

:sub_products
SETLOCAL
Set _item="Coffee Grinder"
Set _price=150
ENDLOCAL & SET _return1=%_item%& SET _return2=%_price%

Multiple SET commands may be added to pass multiple variables, just prefix each with an &
Be aware that any trailing spaces will be added to the variables value.

Improving readability

The 'ENDLOCAL & SET' technique described above can become difficult to read if you have a lot of SET commands all on the same line. This can be made easier to read if you first store all the Set assignments in a single variable (_returns) as shown below (thanks to Ilya Bobyr for this technique)

Set _returns=^
Set _return1=%_item%^&^
Set _return2=%_price%^&^
Set _return3=%_discount%^&^
Set _return4=%_delivery%

Endlocal & %_returns%

In these examples we have used the variable names _return1, _return2 etc, but you can use any names for the return variables, even re-use the exact same variable name inside and outside the ENDLOCAL command (SET _price=%_price%)
Please Leave Your Comment

56). ERASE = Delete one or more files...
(EXPLAIN - DEL)
Delete one or more files.

Syntax
DEL [options] [/A:file_attributes] files_to_delete

Key
files_to_delete : This may be a filename, a list of files or a Wildcard

options
/P Give a Yes/No Prompt before deleting.
/F Ignore read-only setting and delete anyway (FORCE)
/S Delete from all Subfolders (DELTREE)
/Q Quiet mode, do not give a Yes/No Prompt before deleting.

/A Select files to delete based on file_attributes

file_attributes:
R Read-only -R NOT Read-only
S System -S NOT System
H Hidden -H NOT Hidden
A Archive -A NOT Archive

Wildcards: These can be combined with part of a filename

* Match any characters
? Match any ONE character

Examples:

To delete HelloWorld.TXT
DEL HelloWorld.TXT

To delete "Hello Big World.TXT"
DEL "Hello Big World.TXT"

To delete all files that start with the letter A
DEL A*

To delete all files that end with the letter A
DEL *A.*

To delete all files with a .DOC extension
DEL *.DOC

To delete all read only files
DEL /a:R *

To delete all files including any that are read only
DEL /F *

Folders
If a folder name is given instead of a file, all files in the folder will be deleted, but the folder itself will not be removed.

Temporary Files
You should clear out TEMP files on a regular basis - this is best done at startup when no applications are running. To delete all files in all subfolders of C:\temp\ but leave the folder structure intact:

DEL /F /S /Q %TEMP%

When clearing out the TEMP directory it is not generally worthwhile removing the subfolders too - they don't use much space and constantly deleting and recreating them can potentially increase fragmentation within the Master File Table.

Deleting a file will not prevent third party utilities from un-deleting it again, however you can turn any file into a zero-byte file to destroy the file allocation chain like this:

TYPE nul > C:\examples\MyFile.txt
DEL C:\examples\MyFile.txt

Undeletable Files

Files are sometimes created with the very long filenames or reserved names: CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, NUL
To delete these use the syntax: DEL \\.\C:\somedir\LPT1
Alternatively SUBST a drive letter to the folder containing the file.

If a file (or folder) still appears to be 'undeletable' this is often caused by the indexing service.
Right click the file you need to delete, choose properties, advanced and untick "allow indexing" you will then be able to delete the file.
To cure the problem permanently - Control Panel, Add/Remove programs, Win Accessories, indexing service.

Delete Locked files (Typically IE temp files or the Offline cache)
This works on any version of NT, 2000 or XP

Close all applications
Open a command prompt
Click Start, and then Shut Down
Simultaneously press CTRL+SHIFT+ALT.
While you keep these keys pressed, click Cancel in the Shut Down Windows dialog box.
In the command prompt window, navigate to the cache location, and delete all files from the folder (DEL /s)
At the command prompt, type explorer, and then press ENTER.

DELTREE

Previous versions of Windows had the DELTREE command that deletes all files and sub folders.
DEL /s will delete all files
RD /s will remove all files and folders including the root folder.

:: Remove all files and subfolders but NOT the root folder
:: From tip 617 at JsiFAQ.com
@echo off
pushd %1
del /q *.*
for /f "Tokens=*" %%G in ('dir /B') do rd /s /q "%%G"
popd

Normally DEL will display a list of the files deleted, if Command Extensions are disabled; it will instead display a list of any files it cannot find.

ERASE is a synonym for DEL
Please Leave Your Comment

57). EVENTCREATE = Add a message to the Windows event log...
(EXPLAIN - EVENTCREATE (Windows 2003/2008)
Add a message to the Windows event log, requires administrator rights.

Syntax
EVENTCREATE [/S system [/U username [/P [password]]]] /ID eventid
[/L logname] [/SO srcname] /T type /D description

Key:
/S system The remote system to connect to.

/U [domain\]user User credentials under which to execute.

/P [password] Password for user, will prompt if omitted.

/L logname The event log to create an event in.

/T type The type of event to create: SUCCESS, ERROR, WARNING, INFORMATION.

/SO source The source to use for the event A text string that represents the application
or component that is generating the event. Default='eventcreate'

/ID id Event ID, a number between 1 - 1000.

/D description Description text for the new event.

/? Help

Examples:

Add an ERROR to the Application log:
C:\> EVENTCREATE /T ERROR /ID 1000 /L APPLICATION /D "My application error mesaage"

Add a WARNING to the Application log for Application SS64App:
C:\> EVENTCREATE /T WARNING /ID 500 /L APPLICATION /SO SS64App /D "Running low on diskspace"

Add an ERROR to the Application log on Server401:
C:\> EVENTCREATE /S Server401 /T ERROR /ID 250 /L APPLICATION /D "Something bad happened"

Add an ERROR to the Application log on Server401:
C:\> EVENTCREATE /S Server401 /U billg /P password /ID 250 /T ERROR /L APPLICATION /D "Something bad happened"
Please Leave Your Comment

58). EXIT = Quit the current script/routine and set an errorlevel...
(EXPLAIN - EXIT)
Quit the current batch script, quit the current subroutine or quit the command processor (CMD.EXE) optionally setting an errorlevel code.

Syntax
EXIT [/B] [exitCode]

Key
/B When used in a batch script, this option will exit
only the script (or subroutine) but not CMD.EXE

exitCode Sets the %ERRORLEVEL% to a numeric number.
If quitting CMD.EXE, set the process exit code no.

You should never attempt to directly write to the %errorlevel% variable, (i.e. don't try anything like SET errorlevel...) using the EXIT command provides a safe way to alter the value of the built-in errorlevel variable.

Examples

:: Exit if a required file is missing
@echo off
If not exist MyimportantFile.txt Exit /b
Echo The file was found

:: Set the error level to 5
@echo off
call :setError
echo %errorlevel%
goto :eof

:setError
exit /B 5

To make this more flexible you can change the subroutine to set any errorlevel like this:

:setError
exit /B %1

Now you can call the subroutine: call :setError 6 replacing 6 with whatever value you need the errorlevel to be set to.
Please Leave Your Comment

59). EXPAND = Uncompress files...
(EXPLAIN - EXPAND)
Uncompress one or more compressed files.

Syntax
EXPAND Source Destination
EXPAND -r Source Destination
EXPAND -r Source

Options

Source : Source filename or a wildcard

Destination : Destination filename or folder

-r : Rename the files
Please Leave Your Comment

60). EXTRACT = Uncompress CAB files...
(EXPLAIN - EXPAND)
Uncompress one or more compressed files.

Syntax
EXTRACT [options] CAB_file [filenames]

Key
CAB_file : Cabinet file

filenames : Name of the file to extract from the cabinet
Wild cards (*.*) (.) and multiple files are valid

options
/A Process ALL cabinets. (where CABs are linked)

/C If the CAB contains one file then /C will
copy from DMF disks

/D Display CAB directory

/E Extract all (use instead of *.* to extract all files)

/L dir Location to place extracted files (default is current folder)

/Y Overwrite files without any prompt
Please Leave Your Comment

No comments:

Post a Comment

FaceBook