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 9

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

DOS COMMANDS SYNTAX 9, TREASURE--> DOWNLOAD
161). SET = Display, set, or remove environment variables...
(EXPLAIN - SET)
Display, set, or remove CMD environment variables. Changes made with SET will remain only for the duration of the current CMD session.

Syntax
SET variable
SET variable=string
SET /A variable=expression
SET "variable="
SET /P variable=[promptString]
SET "

Key
variable : A new or existing environment variable name
string : A text string to assign to the variable.
expression: : Arithmetic Sum

Also see SetX, VarSearch and VarSubstring for more advanced variable manipulation.

Variable names are not case sensitive but the contents can be. Variables can contain spaces.

The number one problem people run into with SET is having extra spaces around either the variable name or the string, SET is not forgiving of extra spaces like many other scripting languages.

The CMD shell will fail to read an environment variable if it contains more than 8,191 characters.

To display current variables:

Type SET without parameters to display all the current environment variables.

Type SET with a variable name to display that variable SET _department
or use ECHO: ECHO [%_department%]

The SET command invoked with a string (and no equal sign) will display a wildcard list of all matching variables

Display variables that begin with 'P': SET p
Display variables that begin with an underscore SET _

Examples

Storing a text string:

C:\>SET _dept=Sales and Marketing
C:\>set _
_dept=Sales and Marketing

One variable can be based on another, but this is not dynamic
E.g.

C:\>set xx=fish
C:\>set msg=%xx% chips
C:\>set msg
msg=fish chips

C:\>set xx=sausage
C:\>set msg
msg=fish chips

C:\>set msg=%xx% chips
C:\>set msg
msg=sausage chips

Avoid starting variable names with a number, this will avoid the variable being mis-interpreted as a parameter
%123_myvar% < > %1 23_myvar

To display undocumented system variables:

SET "

Prompt for user input

@echo off
Set /P _dept=Please enter Department:
If "%_dept%"=="" goto :sub_error
If /i "%_dept%"=="finance" goto sub_finance
If /i "%_dept%"=="hr" goto sub_hr
goto:eof

:sub_finance
echo You chose the finance dept
goto:eof

:sub_hr
echo You chose the hr dept

The /P switch allows you to set a variable equal to a line of input entered by the user.
The PromptString is displayed before the user input is read. The PromptString can be empty.
The CHOICE command is an alternative to SET /P

To place the first line of a file into a variable:

Set /P _MyVar=<myfilename.txt "="" "_department="

Variable names can include Spaces

A variable can contain spaces and also the variable name itself may contain spaces, therefore the following assignment:
SET my var=MyText
will create a variable called " "_var="" %="" &="" (%substring%)="" (set="" *="" +="" -="" 1="" <<="" ^="" _department="Better" _var="MyText" a)="" a="" actually="" add="" after="" allowing="" alternatively="" an="" and="" appearing="" arithmetic="" avoid="" be="" bracket="" brown="" call="" called="" can="" character.="" command="" create="" current="" deleting="" detected="" divide="" do="" dog="" echo="" environment.="" environment="" equals="" errorlevel="" escape="" evaluated:="" evaluated="" expression="" expressions="" extra="" following="" found="" fox="" if="" in="" include="" is="" issue="" jumps="" just="" lazy="" length="9" like="" lsh="" modulus="" multiply="" my="" name="" need="" no="" not="" note:="" note="" operators:="" or="" output,="" over="" parentheses,="" problems="" quick="" rsh="" set="" sign:="" similarly="" space="" spaces="" start="10" statements="" still,="" string="The" substring="" subtract="" sure="" text"="" text)="" the="" there="" this="" to="" trailing="" type="" use="" using="" var"="" variable="" wanted="" will="" with="" xor="" you="" your="" |="">>
Multiply Variable *=
Divide Variable /=
Add Variable +=
Subtract Variable -=
AND Variable &=
OR Variable |=
XOR Variable ^=
LSH Variable <<= RSH Variable <<= SET /a calculations Enclose any logical expressions in "quotes" Several calculations can be put on one line if separated with commas. Warning: any SET /A calculation that returns a fractional result will be rounded down to the nearest whole integer. Examples: SET /A _result=2+4 (=6) SET /A _result=5 (=5) SET /A _result+=5 (=10) SET /A _result="2<<3" (=16) { 2 Lsh 3 = binary 10 Lsh 3 = binary 10000 = decimal 16 } SET /A _result="5%%2" (=1) { 5/2 = 2 + 2 remainder 1 = 1 } Modulus operator - note that in a batch script, (as opposed to on the command-line), you need to double up the % to %% SET /A will treat any character string in the expression as an environment variable name. This allows you to do arithmetic with environment variable values without having to type any % signs to get the values. SET /A _result=5 + _MyVar Leading Zero will specify Octal Numeric values are decimal numbers, unless prefixed by 0x for hexadecimal numbers, 0 for octal numbers. So 0x12 = 022 = 18 decimal The octal notation can be confusing - all numeric values that start with zeros are treated as octal but 08 and 09 are not valid numbers because 8 and 9 are not valid octal digits. This is often a cause of error when performing date arithmetic. For example SET /a _day=07 will return the value=7, but SET /a _day=09 will return an error. Permanent Changes Changes made using the SET command are NOT permanent, they apply to the current CMD prompt only and remain only until the CMD window is closed. To permanently change a variable at the command line use SetX or in the GUI - Control Panel, System, Environment, System/User Variables Changing a variable permanently with SetX will not affect any CMD prompt that is already open. Only new CMD prompts will get the new setting. You can of course use SetX in conjunction with SET to change both at the same time, but neither SET or SetX will affect other CMD sessions that are already running. When you think about it - this is a good thing. It is also possible (although undocumented) to add permanent env variables to the registry [HKEY_CURRENT_USER\Environment] (using REGEDIT) System Environment variables can also be found in [HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment] Autoexec.bat Any SET statement in c:\autoexec.bat may be parsed at boot time Variables set in this way are not available to 32 bit gui programs - they won't appear in the control panel. They will appear at the CMD prompt. If autoexec.bat CALLS any secondary batch files, the additional batch files will NOT be parsed at boot. This behaviour can be useful on a dual boot PC. If Command Extensions are disabled all SET commands are disabled other than simple assignments like: _variable=MyText
Please Leave Your Comment

162). SETLOCAL = Control the visibility of environment variables...
(EXPLAIN - SETLOCAL)
Set options to control the visibility of environment variables in a batch file.

Syntax
SETLOCAL

SETLOCAL EnableDelayedExpansion

SETLOCAL EnableExtensions | DisableExtensions

Key
EnableDelayedExpansion Expand variables at execution time rather than at parse time.

EnableExtensions Attempt to enable Command extensions.

DisableExtensions Attempt to disable Command extensions.

SETLOCAL on it's own, usually at the start of a batch file, will begin localisation of Environment Variables.

Issuing a SETLOCAL command, the batch script will inherit all current variables from the master environment/session.

Issuing an ENDLOCAL command will restore any environment variables present before the SETLOCAL was issued.

If a batch script does not use SETLOCAL and ENDLOCAL then all variables will be Global, i.e. visible and modifiable by other scripts.

Although global variables are easy to work with they are not good practice - for example if you have several batch scripts dealing with filenames (and these scripts may be CALLing one another), the first script may have a variable called _filename, the second script a different variable called file-name (a different name to avoid conflicting with the first script) a third script now needs something like file_name this quickly becomes very difficult to manage.

With local variables you are free to use the same variable names in multiple batch scripts - there is no conflict because the local variables are not visible to any other script.
Local Variables can be passed from one batch routine to another with the ENDLOCAL command.

EnableDelayedExpansion

Setting EnabledDelayedExpansion will cause each variable to be expanded at execution time rather than at parse time.
EnableDelayedExpansion is Disabled by default.

Overloading a variable

SETLOCAL can be used more than once in the same batch file so that multiple values can be stored in the same Environment Variable. To keep track of variable definitions, SETLOCAL and ENDLOCAL statements should be paired.

@echo off
SETLOCAL
::Standard commission
SET _Commission=20
echo %_Commission%

::Premium commission
SETLOCAL
set _Commission=30
echo %_Commission%

::back to Standard commission
ENDLOCAL
echo %_Commission%

DISABLEEXTENSIONS

Command Extensions are enabled by default, there is rarely any need to disable them.

If Command Extensions are permanently disabled or if a script is running under the Windows 95 command processor command.com then SETLOCAL ENABLEEXTENSIONS will not be able to restore them.

A batch file to warn if command extensions are not available:

VERIFY errors 2>nul
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 echo Unable to enable extensions

Errors

SETLOCAL will set an ERRORLEVEL if given an argument: It will be zero if one of the two valid arguments is given and one otherwise.
Please Leave Your Comment

163). SETX = Set environment variables permanently...
(EXPLAIN - SETX.exe(WINDOWS 7)
Set environment variables permanently

SETX can be used to set Environment Variables for the machine or currently logged on user:

SETX Variable Value

SETX Variable Value -m

Key:
-m Set the value in the Machine environment (HKLM)
Default is User (HKCU)

SetX can also be used in modes to edit the Registry or edit CR-LF text files, (like win.ini) for most purposes these tasks are better done with other tools in the resource kit, e.g. the REG command.

Because SetX writes variables to the master environment in the registry. Edits will only take effect when a new command window is opened - they do not affect the current command session.

Deleting variables
A value of "" (empty quotes) will appear to delete the variable - it's not shown by SET but the variable name will remain in the registry. Either use the GUI (recommended) or delete the value from the registry with REG

REG delete HKCU\Environment /V _myvar

Deleting a variable with REG does not take effect until next logon due to caching of registry data. The type is REG_EXPAND_SZ.

Examples:

Set the variable _mypc to be COMPAQ in the users permanent environment:

SetX _mypc COMPAQ

Delete the variable _mypc in the users permanent environment:

REG delete HKCU\Environment /V _mypc

Set the variable _myTimeZone in both the immediate user session and the permanent environment:

SET _myTimeZone=GMT
SetX _myTimeZone GMT


Store the value of %my_important_var% in a second environment variable.
SetX _mybackupvar %my_important_var%

Sets the value of _mypath to be equal to the value of the %PATH% environment variable, _mypath will then remain the same even if the PATH variable changes in the future:
SetX _mypath ~PATH~

Machine variables

These are stored on the machine and won't follow a users roaming profile.
To set a machine variable (-m) requires Administrator rights.

Create a machine variable:

SetX _myvar COMPAQ -m

Delete a machine variable:

REG delete "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /V _myvar
Please Leave Your Comment

164). SFC = System File Checker...
(EXPLAIN - SFC (Windows XP, Server 2003, Win 7)
System File Checker

Syntax
Sfc [/Scannow] [/Scanonce] [/Scanboot] [/Revert] [/Purgecache] [/Cachesize=x]
Key
/Scannow Scan all protected system files immediately and replace
incorrect versions with correct Microsoft versions.
May require access to the Windows installation source files.

/Scanonce Scan all protected system files one time when you restart your computer.
May require access to the Windows installation source
files when you restart the computer.
The SfcScan DWORD value is set to 2 in the following registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

/Scanboot Scan all protected system files every time you start your computer.
May require access to the Windows installation source files every
time you start the computer.
The SfcScan DWORD value is set to 1 in the following registry key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

/Revert Return scan to the default setting
(do not scan protected files when you start the computer).
The default cache size is not reset when you run this command.

/Purgecache Purge the file cache and scan all protected system files immediately.
May require access to the Windows installation source files.

/Cachesize=x Set the file cache size to x megabytes (MB).
The default size of the cache is 50 MB.
This command requires you to restart the computer, and then run
the /purgecache command to adjust the size of the on-disk cache.
This command sets the SfcQuota DWORD value to x in the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

Under Windows 7, SFC must be run from an elevated command prompt.
Please Leave Your Comment

165). SHARE = List or edit a file share or print share...
(EXPLAIN - Share.vbs)
List or edit a file share or print share (on any computer)

Although missing from recent Resource Kits, this VBS script does still work under recent versions of Windows. The preferred method for creating shares is the RMTShare command, which can also grant permissions.

Syntax:
List Shares
Share.vbs /L [/S ] [/U ] [/W ] [/O ]

Create a Share
Share.vbs /C /N /P [/T ] [/V ]
[/S ] [/U ] [/W ] [/O ]
Delete a Share
Share.vbs /D /N
[/S ] [/U ] [/W ] [/O ]

Key:

/L List
/C Create
/D Delete
/N name Name of the share to be created or deleted.
/P path Path of the share to be created.
/v description A description for the share.
/T type Type of the share to be created. (Disk, Printer, IPC or Special)
/S server A machine name.
/U username The current user's name.
/W password Password of the current user.
/O outputfile Output file name.

Examples:

List the shares on the machine \\Frodo

cscript Share.vbs /L /s Frodo

Create a file share called "scratch" on the local machine:

cscript Share.vbs /c /n scratch /p "c:\my shared files" /t Disk /v "project files"

Delete the share named "scratch" on the machine \\Frodo

cscript Share.vbs /d /n scratch /s Frodo
Please Leave Your Comment

166). SHIFT = Shift the position of replaceable parameters in a batch file...
(EXPLAIN - SHIFT)
Change the position of command line parameters in a batch file.

Syntax
SHIFT [/n]

Key
/n Start at the nth argument, where n may be between zero and eight.



Relative pathnames

Examples:

Given %1=the, %2=quick, %3=brown
SHIFT
will result in %1=quick, %2=brown
A second
SHIFT
will result in %1=brown

Given %1=the, %2=quick, %3=brown, %4=fox
SHIFT /2
will result in %1=the, %2=brown, %3=fox

Parse Command Line Arguments

:start
if "%1"=="" (goto :main)
:: Do whatever with token %1
Echo [%1]
:: Shift %2 into %1
SHIFT
goto :start

:main
::

The parameter %0 will initially refer to the path that was used to execute the batch - this could be MyBatch.cmd if in the current directory or a full path like C:\apps\myBatch.cmd

If SHIFT is used to move a text parameter into %0 then any references to %0 will refer instead to the current working directory, unless the new parameter value happens to contain a valid path.

For example:

%0\..\MyExecutable.exe

will run the MyExecutable from the same directory as the Batch file.

If the following parameter is passed to myBatch.cmd

myBatch.cmd D:\utils\

Then the following commands in myBatch will run MyExecutable.exe from the directory D:\utils\

SHIFT
%0\..\MyExecutable.exe

If Command Extensions are disabled, the SHIFT command will not support the /n switch
Please Leave Your Comment

167). SHORTCUT = Create a windows shortcut (.LNK file)...
(EXPLAIN - SHORTCUT.exe)
Create a windows shortcut (.LNK file)

Syntax
SHORTCUT [options]

Key
Source options
-t target : The path and file name of the application/document to open.
-a arguments : The arguments passed when the shortcut is used.
-d directory : The folder to start the application in.
-i iconfile : The file the icon is in.
-x index : The index into the icon file.

options for the shortcut file to be created

-n name : The path and file name (.LNK) of the shortcut file.
-c : Change existing shortcut.
-r : Resolve broken shortcut.
-f : Force overwrite of an existing short cut.
-s : Make shortcut simple (don't use LinkResolve)

Export options
-u [spec] : ECHO the contents of an existing shortcut.
'all' is the same as 'natdix' but the letters
of 'natdix' specify the options to be exported
(the same option can be specified more than once
e.g. -u natn)
-l logfile : Save any error messages in the specified file

If shortcut.exe fails to create a new shortcut, it does NOT set an errorlevel.

Example

@ECHO off
MD %userprofile%"\start menu\programs\MY APP"
SHORTCUT -f -t C:\MyApp.exe -n %userprofile%"\start menu\programs\MY APP\MY APP"

For Windows XP and more recent systems, you are better off using a little .vbs script, as WSH is built-in from XP onwards, call the script like so:
CSCRIPT C:\myshortcut.vbs

Optional sections in the VBscript below are commented out:

Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\MyShortcut.LNK"
Set oLink = oWS.CreateShortcut(sLinkFile)

oLink.TargetPath = "C:\Program Files\MyApp\MyProgram.EXE"
' oLink.Arguments = ""
' oLink.Description = "MyProgram"
' oLink.HotKey = "ALT+CTRL+F"
' oLink.IconLocation = "C:\Program Files\MyApp\MyProgram.EXE, 2"
' oLink.WindowStyle = "1"
' oLink.WorkingDirectory = "C:\Program Files\MyApp"
oLink.Save

Shortcut: NTFS file system tracking

If a shortcut to a file breaks because the destination file has moved, then by default Windows will attempt to automatically locate the shortcut destination by performing a search (this only applies to NTFS partitions). To turn this off - add a DWORD value of 1 to the registry:

HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
NoResolveTrack=1

Shortcut: Auto LinkResolve

By default shortcuts will include the destination machine, even for a target like C:\MyFile.doc
This is not immediately visible until the shortcut.LNK file is copied to another machine, the shortcut target will then be automatically updated to point back to \\Machine1\c$\MyFile.doc
To turn this behaviour off use shortcut.exe -s or add a DWORD value of 1 to the registry (before creating the shortcut):

HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
"LinkResolveIgnoreLinkInfo"=1

Favourites
Often confused with shortcuts, Internet Explorer Favourite (.URL) files are simple text files which you can create with a few ECHO statements.
Please Leave Your Comment

168). SHOWGRPS = List the NT Workgroups a user has joined...
(EXPLAIN - SHOWGRPS)
List the Workgroups a user has joined.

Syntax
SHOWGRPS domain\username

SHOWGRPS username

If no username is specified SHOWGRPS will list the workgroups for the currently logged in user.

Example

SHOWGRPS ss64domain\user05
Please Leave Your Comment

169). SHOWMBRS = List the Users who are members of a Workgroup...
(EXPLAIN - SHOWMBRS)
List all the users who are members of a Workgroup.

Syntax
SHOWMBRS domain\Workgroup

SHOWMBRS Workgroup

A workgroup must be specified.

Example:

SHOWMBRS wg_finance
Please Leave Your Comment

170). SHUTDOWN = Shutdown the computer...
(EXPLAIN - SHUTDOWN.exe)
Shutdown the computer

Syntax
SHUTDOWN [logoff_option] [/m \\Computer] [options]

logoff_options:
/i Display the GUI (must be the first option)
/l Log off. This cannot be used with /m or /d option
/s Shutdown
/r Shutdown and Restart
/a Abort a system shutdown.
(only during the time-out period)
/p Turn off the local computer with no time-out or warning
(only with /d)
/h Hibernate the local computer (only with /f )
/e Document the reason for an unexpected shutdown of a computer

Options:

/m \\Computer : A remote computer to shutdown.

/t:xxx : Time until system shutdown in seconds.
The valid range is xxx=0-600 seconds. [default=30]
/c "Msg" : An optional shutdown message [Max 127 chars]

/f : Force running applications to close.
This will not prompt for File-Save in any open applications.
so will result in a loss of all unsaved data!!!

/d u:xx:yy : List a USER (unplanned) reason code for the shutdown.
/d P:xx:yy : List a PLANNED reason code for the shutdown.
xx Specifies the major reason code (0-255)
yy Specifies the minor reason code (0-65536)

Options in bold are for Windows 2003 and later

When using this command to reboot a server, the shutdown process will normally allow 30 seconds to ensure each running service has time to stop. Services are shutdown in alphabetical order. The shutdown may be done made faster if the services are first halted in a specific order using NET STOP or SC.

Reason codes:
E = Expected
U = Unexpected
P = Planned (C = customer defined)

Type Major Minor Title
U 0 0 Other (Unplanned)
E 0 0 Other (Unplanned)
E P 0 0 Other (Planned)
U 0 5 Other Failure: System Unresponsive
E 1 1 Hardware: Maintenance (Unplanned)
E P 1 1 Hardware: Maintenance (Planned)
E 1 2 Hardware: Installation (Unplanned)
E P 1 2 Hardware: Installation (Planned)
P 2 3 Operating System: Upgrade (Planned)
E 2 4 Operating System: Reconfiguration (Unplanned)
E P 2 4 Operating System: Reconfiguration (Planned)
P 2 16 Operating System: Service pack (Planned)
2 17 Operating System: Hot fix (Unplanned)
P 2 17 Operating System: Hot fix (Planned)
2 18 Operating System: Security fix (Unplanned)
P 2 18 Operating System: Security fix (Planned)
E 4 1 Application: Maintenance (Unplanned)
E P 4 1 Application: Maintenance (Planned)
E P 4 2 Application: Installation (Planned)
E 4 5 Application: Unresponsive
E 4 6 Application: Unstable
U 5 15 System Failure: Stop error
E 5 19 Security issue
U 5 19 Security issue
E P 5 19 Security issue
E 5 20 Loss of network connectivity (Unplanned)
U 6 11 Power Failure: Cord Unplugged
U 6 12 Power Failure: Environment
P 7 0 Legacy API shutdown

Examples

Shutdown the local system immediately:

SHUTDOWN /s

Restart the local system in 60 seconds time and specify the reason "Application: Installation (Planned)" :

SHUTDOWN /r /t:60 /d P:4:2

Restart the remote system server64 and specify the reason "Security Fix, Planned"

SHUTDOWN /r /m \\server64 /d P:2:17
Please Leave Your Comment

171). SLEEP = Wait for x seconds...
(EXPLAIN - SLEEP.exe)
Add a fixed delay to a batch file

Syntax
SLEEP time
Key
time : the number of seconds to pause

For example:
To pause for an hour before running the next command in a batch file:

SLEEP 3600

Alternative
A fixed delay can also be produced by the PING command with a loopback address:

e.g. for a delay of 60 seconds:
PING -n 61 127.0.0.1>nul
Please Leave Your Comment

172). SLMGR = Software Licensing Management (Vista/2008)...
(EXPLAIN - slmgr.vbs (Vista and Server 2008)
Software Licensing Management Tool (C:\windows\system32\slmgr.vbs)

Syntax
slmgr [MachineName [Username Password]] [Option]

Key
-dli Display the current license information with activation
status and partial product key.

-dlv Verbose, similar to -dli but with more information.

-dti Display Installation ID for offline activation

-ipk Key Enter a new product key supplied as xxxxx-xxxxx-xxxxx-xxxxx-xxxxx

-xpr Show the expiry date of current license (if not permanently activated)

-upk Uninstall current installed product key and return license status back to trial state.

-ato Activate Windows license and product key against Microsoft's server.

-atp Confirmation_ID Activate Windows with user-provided Confirmation ID

-skms activationservername
or
-skms port
or
-skms activationservername:port
Set the KMS server and the port used for KMS activation
(where supported by your Windows edition)

-rearm Reset the evaluation period/licensing status and activation state of the machine

-ckms Clear the name of KMS server used to default and port to default.

-cpky Clear product key from the registry (prevents disclosure attacks)

-ilc License_file Install license

-rilc Re-install system license files

machinename The machine to administer, by default the current local machine.

username An administrator equivalent user account for the computer.

password The password for the user account.

Running slmgr.vbs requires elevated administrator privileges.

Examples

C:\windows\system32\slmgr.vbs wkstn0064 administrator password1 -dli
slmgr.vbs -skms 192.168.10.1:8090
slmgr.vbs -skms KMSServer:8090
Please Leave Your Comment

173). SOON = Schedule a command to run in the near future...
(EXPLAIN - SOON.exe)
Schedule a command to run in the near future (calls the AT command)

Syntax
SOON [\\computername] delay [/interactive] "command"
SOON /i:[on|off]

Key
delay : When the command should run, in SECONDS from now.
default=5

/interactive : Allows any user to see the job as it runs,
this allows testing and monitoring of the
command.
You can specify /interactive as just /i

computername : the UNC name of a remote machine

/i:on : Make /interactive the default behaviour
use SOON /i:off to restore normal behaviour

SOON schedules jobs to run at a time relative to the current time in "seconds from now"
It is otherwise identical to the AT command but saves calculating an exact start time.

As with all AT jobs you should test your SOON scripts by using the /INTERACTIVE option.

In many cases SCHTASKS may be a better option.
Please Leave Your Comment

174). SORT = Sort input...
(EXPLAIN - SORT)
Sort will accept a redirected or piped file input and TYPE the file, sorted line by line.

Syntax
SORT [options]

Options
/R : Reverse sort order (Z to A, 9 to 0)

/+n : Sort the file ignoring the first 'n' characters in each row.
The default is to sort using all the chars in each row.

/L[OCALE] locale

Override the system default locale with
The "C" locale yields a faster
collating sequence.
The sort is always case insensitive.

/M[EMORY] kilobytes

The amount of RAM to use for the sort.
The best performance is usually achieved by
not specifying a memory size.

SORT will only create a temporary file
when required by limitations in available memory.

/REC[ORD_MAXIMUM] characters

The maximum number of characters in a row or record
(default 4096, maximum 65535)

[drive:][pathname]

The file to be sorted.
If not specified, the standard input is sorted.
Specifying an input file is faster than
redirecting the same file as standard input.

/T[EMPORARY] [drive:][path]

The path of the directory to hold
SORT's working storage, in case the data
does not fit in RAM. The default is %temp%

/O[UTPUT] [drive:][pathname]

The file where the sorted input is to be stored.
If not specified, the data is written to standard output.
Specifying an output file is faster than redirecting
standard output to a file.

Redirecting a file into SORT

SORT < pathname Piping a command into SORT command | SORT Piping the output from SORT into a file command | SORT > pathname2
SORT < pathname > pathname2

Piping the output from SORT and appending to an existing file

command | SORT >> pathname2
SORT < pathname >> pathname2
Please Leave Your Comment

175). START = Start a program or command in a separate window...
(EXPLAIN - START)
Start a specified program or command in a separate window.

Syntax
START "title" [/Dpath] [options] "command" [parameters]

Key:
title : Text for the CMD window title bar (required)
path : Starting directory
command : The command, batch file or executable program to run
parameters : The parameters passed to the command

Options:
/MIN : Minimized
/MAX : Maximized
/WAIT : Start application and wait for it to terminate
/LOW : Use IDLE priority class
/NORMAL : Use NORMAL priority class
/HIGH : Use HIGH priority class
/REALTIME : Use REALTIME priority class

/B : Start application without creating a new window. In this case
^C will be ignored - leaving ^Break as the only way to
interrupt the application
/I : Ignore any changes to the current environment.

Options for 16-bit WINDOWS programs only

/SEPARATE Start in separate memory space (more robust)
/SHARED Start in shared memory space (default)

Notes:

Always include a TITLE this can be a simple string like "My Script" or just a pair of empty quotes ""
According to the Microsoft documentation, the title is optional, but you may have problems if it is omitted.

Document files may be invoked through their file association just by typing the name of the file as a command.
e.g. START "" WORD.DOC would launch the application associated with the .DOC file extension

Examples

START "My Login Script" /Min Login.cmd

START "" /wait MySlowProgram.exe

Printers
A new printer can be installed very quickly (and the driver downloaded) with the command:

START \\print_server\printer_name

Setting a Working Directory
To start an application and specify where files will be saved:

START /Dc:\Documents\ /MAX "Maximised Notes" notepad.exe

Forcing a Sequence of Programs
If you require your users to run a sequence of 32 bit GUI programs to complete a task, create a batch file that uses the start command:

@echo off
start /wait /b First.exe
start /wait /b Second.exe
start /wait /b Third.exe

Create a shortcut to this batch file and place it on the Start menu or desktop. Set it to run minimized.
When the user double-clicks the shortcut, runs.
When terminates, runs
When terminates, runs

An alternative method is to run a .BAT batch file under command.com (16 bit)

If Command Extensions are disabled, the START command will no longer recognise file Associations, and will not automatically evaluate the COMSPEC variable when starting a second CMD session.

Missing file extensions
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 executing a command, if there is no match on any extension, then Windows will look to see if the name, without any extension, matches a directory name and if it does, the START command will launch Explorer on that path.
Please Leave Your Comment

176). SU Switch User...
(EXPLAIN - SU)
Switch User.

Syntax
SU "[cmdline]" [domain] [[Winsta\]Desktop] [options]

Key
cmdline The command to run (default =%comspec%)
domain The domain for the user account ('.' = local m/c)
Winsta\Desktop The profile to load (default = current)

Options

-cb console bypass
-dn do not switch to new desktop
-g GUI option
-l load the .Default user registry hive
-w use current registry hive
-e Inherit parent environment
-b batch logon
-i interactive logon
-s service logon
-n network logon
-v verbose

All LogOn Types require specific User Rights to be granted...
SeNetworkLogonRight, SeServiceLogonRight, SeInteractiveLogonRight, SeBatchLogonRight

The RUNAS command is a lot easier to use!
Please Leave Your Comment

177). SUBINACL = Edit file and folder Permissions, Ownership and Domain...
(EXPLAIN - SUBINACL.exe)
Display or modify Access Control Entries (ACEs) for file and folder Permissions, Ownership and Domain.

Access Control Lists apply only to files stored on an NTFS formatted drive, each ACL determines which users (or groups of users) can read or edit the file. When a new file is created it normally inherits ACL's from the folder where it was created.

Syntax
SUBINACL [/noverbose] /object_type object_name [/action=parameter] [/help]

Key
object_type: service e.g. /service Messenger \\ServerName\Messenger
keyreg e.g. /keyreg HKEY_CURRENT_USER\Software
/keyreg \\Srv\HKEY_LOCAL_MACHINE\KeyPath
file e.g. /file *.obj /file c:\test.txt
/file \\ServerName\Share\Path
subdirectories manipulate files in specified directory and all subdirectories

object_name : This will vary according to the object_type - see the examples above

action : setowner=owner
will change the owner of the object e.g. /setowner=MyDomain\Administrators

replace=SamName\OldAccount=DomainName\New_Account
will replace all ACE (Audit and Permissions) in the object
e.g. /replace=MyOldDomain\Finance=NEWDOM\Finance

changedomain=OldDomainName=NewDomainName
will replace all ACEs with a Sid from OldDomainName
with the equivalent Sid found in NewSamServer
e.g. /changedomain=MyOldDomain=NEWDOMAIN
This option requires a trust relationship with the server containing the object.

Examples:

subinacl can do everything that cacls and xcacls can do and more besides.

List permissions to log file:
subinacl /noverbose /nostatistic /outputlog=my.log /subdirectories "C:\Program Files\My Folder" /display

Restore Permissions:
subinacl /nostatistic /playfile my.log

Change owner :
subinacl /file C:\demofile.doc /setowner=MYDOMAIN\BillG

Bugs

Running subinacl against a subfolder, as in the example above will affect just that folder and it's contents. However if you run subinacl against a folder in the root of the drive it will scan the entire drive for folders matching that name (which can take some time).
e.g.
subinacl /subdirectories "C:\Spud"
Will also match
C:\Program Files\Spud
C:\Documents and Settings\Spud etc
Please Leave Your Comment

178). SUBST = Associate a path with a drive letter...
(EXPLAIN - SUBST)
Substitute a drive letter for a network or local path.

Syntax
SUBST drive_letter: path

SUBST

SUBST drive_letter: /D

Key
SUBST with no parameters will display current SUBST drives

/D : Delete the drive_letter substitution.

Compared to mapping a drive with NET USE the SUBST command allows mapping to a subfolder of a drive share - for the storage of user profiles this reduces the number of shares you need to create on the server.

Notes
Under NT 4 SUBST'ed drives could be disconnected using the Explorer GUI - this was fixed in Windows 2000.

In Windows 2000 (and above) you may have problems creating, accessing and deleting drive mappings with SUBST.

However under Win 2K/XP the functionality of the NET USE command is improved so you can now do
NET USE g: \\server\share\folder1\folder2

If the network resource is unavailable (ie the server is down) SUBST will continually retry - unlike NET USE which will try to connect once and fail - depending on your application this may be a good or a bad thing - a subst drive that is not available will badly impact performance of most applications.

Notice that when SUBST is used against a local shared folder, it will create a RECYCLER for that drive. The RECYCLER is not removed when the drive substitution is removed, but can be deleted manually.
Please Leave Your Comment

179). SYSTEMINFO = List system configuration...
(EXPLAIN - SYSTEMINFO)
List system configuration

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

Key:
/S system Remote system to connect to.
/U [domain\]user User context under which to execute.
/P [password] Password for the given user (will prompt if omitted)
/FO format Output format: TABLE, LIST or CSV
/NH No "Column Header" in the Table/CSV output

The output includes OS configuration, security info, product ID, RAM, disk space, and network cards.

Examples

SYSTEMINFO
SYSTEMINFO |find "Total Physical Memory:"
SYSTEMINFO /S wkstn6324
SYSTEMINFO /S wkstn6325 /FO CSV /NH >>pcaudit.csv
Please Leave Your Comment

180). TASKLIST = List running applications and services...
(EXPLAIN - TASKLIST)
TaskList displays all running applications and services with their Process ID (PID) This can be run on either a local or a remote computer.

Syntax
tasklist options

Options:

/s computer Name or IP address of a remote computer
don't use backslashes. Default = local computer.

/u domain\user [/p password]]
Run under a different account

/svc List information for each process without truncation.
Valid when /fo=TABLE. Cannot be used with /m or /v

/m [ModuleName]
Show the processes that include the given module.

/v Verbose task information

/fo {TABLE|LIST|CSV}]
Output format, the default is TABLE.

/nh No Headers in the output (does not apply to LIST output)

/fi FilterName [/fi FilterName2 [ ... ]]
Apply one of the Filters below:

Imagename eq, ne String
PID eq, ne, gt, lt, ge, le Positive integer.
Session eq, ne, gt, lt, ge, le Any valid session number.
SessionName eq, ne String
Status eq, ne RUNNING | NOT RESPONDING
CPUTime eq, ne, gt, lt, ge, le Time hh:mm:ss
MemUsage eq, ne, gt, lt, ge, le Any valid integer.
Username eq, ne User name ([Domain\]User).
Services eq, ne String
Windowtitle eq, ne String
Modules eq, ne String

Examples:

List the services running under each process:

TASKLIST /svc

List the services running under each SvcHost process:

TASKLIST /FI "imagename eq svchost.exe" /svc

List the services running now:

TASKLIST /v /fi "STATUS eq running"

List the services running under a specific user account:

TASKLIST /v /fi "username eq SERVICE_ACCT05"
Please Leave Your Comment

No comments:

Post a Comment

FaceBook