Manage Learn to apply best practices and optimize your operations.

Ten hidden Windows command prompt tricks


Run multiple Windows commands from the command prompt

Source:  Nirmal Sharma; Photograph: Getty Images/iStockphoto

You can run multiple Windows commands in one go from the command prompt. For example, you can start or stop a service from a command prompt by typing "Net Start/Stop." What if you need to restart a service from the command prompt? In that case, you can use a double ampersand -- && -- which allows you to run multiple "Net" commands in one line to first stop and then restart the service.

View All Photo Stories

Join the conversation

1 comment

Send me notifications when other members comment.

Please create a username to comment.

Once again, the ampersand and double ampersand is misrepresented.

Use a single ampersand to chain commands together so that they will ALL execute.

If you use the double ampersand, the second command will ONLY execute if the first one is successful.

Similarly, if you use a double vertical bar, the second command will only execute if the first one fails.


DIR C:\FunnyDir & ECHO Done

Will ECHO Done no matter if C:\FunnyDir exists or not.


DIR C:\FunnyDir && ECHO Done

Will only ECHO Done if FunnyDir Exists


DIR C:\FunnyDir || ECHO Done

Will only ECHO Done if C:\FunnyDir doesn't exist.

The double bars are very useful for flow control. An example that I use involves connecting to a VPN and launching an RDP session if the connection works:

RASDIAL remote userid password || GOTO :EOF
START /MAX /WAIT MSTSC /V remoteserver
RASDIAL remote /disconnect

If the first RASDIAL fails, the batch file exists peacefully (GOTO :EOF). If the first RASDIAL is successful, and RDP session is started and the RASDIAL session will be disconnected when the RDP session ends.