Tag Archives: windows

Restart, shutsdown, logoff Windows from command line

It’s often need to restart, shutsdown, logoff Windows from command line. For example, if you connect to OS via remote desktop protocol you can’t restart/shutdown it from UI.
In such case you can use next:

shutdown -r
restarts os

shutdown -s
shutdown os

shutdown -l
logoff os

shutdown -t xx
where xx is number of seconds to wait till shutdown/restart/logoff

shutdown -i
gives you a dialog box to fill in what function you want to use

shutdown -a
aborts the previous shutdown command....very handy!

Additional options:

force the selected action

Thanx to http://stackoverflow.com/a/162305

Logical operators AND, OR in batch

There is no method to combine operators in windows BATCH command shell.
But we can easily emulate it!

For AND operator use next snippet:

if %var% GEQ 1 (
    if %var% LEQ 10 (
        // do...

For OR operator we have to use additional variable:

set result=false

if %var% LEQ 0 set result=true
if %var% GEQ 10 set result=true

if "%result%" EQU "true" (
   // do...

Thanx to http://stackoverflow.com/a/2143396

Run multiple bat files from single bat file

Windows batch file allows to run another batch file inside of it. There are 2 common way to do it:
1. Using CALL command:

2. Using START command:

The difference between them is the START command runs asynchronously, i.e. it doesn’t wait for finishing previous execution!
Instead of CALL command which is ok for sequential execution.

Thanx to http://stackoverflow.com/a/1104009

Delete files and folders with long names in Windows

Using command line you can delete files and folders with long names:


Unlock file in Windows with ProcessExplorer

It is often occurs locked files. How to unlock file from granted process? Very simple!
Just use ProcessExplorer from Windows Sysinternals.
Download here ProcessExplorer

To perform unlocking, click Ctrl+F and find you file. It’ll show to you the process locker.
Kill them and make fun!

Symbolic link in Windows


To make you work more comfortable and reject you from duplicated task for file edit use symbolic links. It is quite easy – just use MKLINK command in windows!

MKLINK [[/D] | [/H] | [/J]] Link Target

        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    specifies the new symbolic link name.
        Target  specifies the path (relative or absolute) that the new link
                refers to.


  mklink someCommonFile.config C:\project\someCommonFile.config

More info about links at http://krosinski.blogspot.com/2012/10/hard-links-vs-symbolic-links.html