Windows commands
All supported versions of Windows (server and client) have a set of Win32 console commands built in.
This set of documentation describes the Windows Commands you can use to automate tasks by using scripts or scripting tools.
Prerequisites
The information that is contained in this topic applies to:
- Windows Server 2019
- Windows Server (Semi-Annual Channel)
- Windows Server 2016
- Windows Server 2012 R2
- Windows Server 2012
- Windows Server 2008 R2
- Windows Server 2008
- Windows 10
- Windows 8.1
Command shell overview
The Command shell was the first shell built into Windows to automate routine tasks, like user account management or nightly backups, with batch (.bat) files. With Windows Script Host you could run more sophisticated scripts in the Command shell. For more information, see cscript or wscript. You can perform operations more efficiently by using scripts than you can by using the user interface. Scripts accept all Commands that are available at the command line.
Windows has two command shells: The Command shell and PowerShell. Each shell is a software program that provides direct communication between you and the operating system or application, providing an environment to automate IT operations.
PowerShell was designed to extend the capabilities of the Command shell to run PowerShell commands called cmdlets. Cmdlets are similar to Windows Commands but provide a more extensible scripting language. You can run Windows Commands and PowerShell cmdlets in Powershell, but the Command shell can only run Windows Commands and not PowerShell cmdlets.
For the most robust, up-to-date Windows automation, we recommend using PowerShell instead of Windows Commands or Windows Script Host for Windows automation.
You can also download and install PowerShell Core, the open source version of PowerShell.
Incorrectly editing the registry may severely damage your system. Before making the following changes to the registry, you should back up any valued data on the computer.
To enable or disable file and directory name completion in the Command shell on a computer or user logon session, run regedit.exe and set the following reg_DWOrd value:
To set the reg_DWOrd value, use the hexadecimal value of a control character for a particular function (for example, 0 9 is Tab and 0 08 is Backspace). User-specified settings take precedence over computer settings, and command-line options take precedence over registry settings.
Command-line reference A-Z
To find information about a specific command, in the following A-Z menu, click the letter that the command starts with, and then click the command name.
Send commands to other command-line programs
Is there a way, to send commands to another command-line program?
‘Cause i have a special command-line program, but I can’t send commands to it using syntax like program.exe something_to_do
the program executes something like this: («here syntax» is where i want to input text to and also enter to start)
the program in code looks something like this:
Well, i guess so cause it wasnt me who made it (btw: off course its not called TheWhateverCommandLineProgram)
3 Answers 3
If you just want to give keyboard input to a commandline program you can just use echo and pipe it:
If you need more lines, then write them to a file and use input redirection:
I’m not 100% sure I understand what you’re looking for. Here’s two options:
You have two windows, each running a batch program. Let’s say they are called myscript1.bat and myscript2.bat . You want to send a set of commands from myscript1.bat to be executed by myscript2.bat
You have a single batch script named myscript.bat , which executes a single program named program.exe . You want program.exe to execute some commands, or do some something.
Are either of these what you’re looking for? Here’s some idea:
Make myscript1.bat create a third file, mycommands.bat . Once myscript2.bat sees the file mycommands.bat exists, it will execute it and delete it. (Wow. Lame.)
Use Windows Scripting Host command (it’s built in to Windows since Win2K) or Powershell (usually on most computers nowadays, if they have been updated). Either of these can send keystrokes to another program. Using those keystrokes, you can control the other program.
How can I send a notification to a Windows 10 computer from the command line
I’d like to create/send native Windows notifications from the command-line as part of a few automated tasks that I have set up, both on my local machine and for similar tasks on my home server. Both computers run Windows 10, and are on the same network.
I’m looking to receive the notifications from both computers in the action centre on my main computer.
Is there a command-line tool I can use to accomplish this?
4 Answers 4
Another way is the built in MSG.exe command that has been there since Vista. From a command prompt there the following:
msg /server:poseidon daniel «Please contact help desk immediately!»
Server is the name of computer you are sending the message to and daniel is a valid user name of the person using that computer. Fast and simple without any extra downloads.
If you want to create a native windows notification (a popup in bottom-right corner and persistant in notification center), you could take the following Powershell snippet as a template.
It looks like this in notification center.
You can use Growl for Windows for this. You’d need growlnotify to send the message and the full application where you receive the notification. As per the comments you will need a plugin for native toast notifications.
On the receiving end, you will also need to enable notifications from other PCs and to set up a password.
We’re assuming the system where the full GFW package is installed is 192.168.1.110.
On the sending end growlnotify.com /r:»test1″ /a:»test1″ /host:192.168.1.110 /pass:test boo registers the application. You need to do this once I prefer the batch varient here cause it has more useful warnings for initial setup. You can switch to the exe file once you know things work.
and something like growlnotify.com /n:»test1″ /a:»test1″ /host:192.168.1.110 /pass:test /t:title message would work after that to send messages.
For anything else, you can probably refer to the docs and hack together something to fill in the message content.
Tested between two windows 10 systems and it works for me.
If you want to send messages from linux to a GFW or growl for mac instance, you can use gntp-send
UPDATE 19/05/2018:
Pullover can no longer create native Windows notifications as of version 1.3.0 (due to fixes to support the Fall Creators Update), so this is now only a partial answer to the question. It’s still a viable way to get notifications from/via Pushover, but they won’t be native.
Something I’ve been using for a while for mobile notifications is Pushover, which accepts notifications via an HTTP request and sends them to all (or a selection of) devices registered to your account. I’ve been using curl to generate and send the necessary HTTP requests. (I know, not very ‘Windows’y).
Yesterday I found out Pushover now has official desktop support for its notifications via the browser, and third third-party support from via a desktop client called Pullover which displays any notifications received from Pushover as native Windows notifications. Note that receiving desktop notifications requires a license.
Here are the steps required to send a notification via curl:
- Register for an account and log in
- Download and install Pullover
- Login to Pullover and give your computer a device name
- You should receive a «Welcome to Pushover!» notification confirming that notifications are working
- Note down your User Key displayed on your account page
- Scroll down, and click Register an Application/Create an API Token
- Enter a Name , and select Script as the Type
- Accept the T&Cs, and click Create Application
- Note down the API Token/Key you are given
- Download curl and stick it somewhere in your %PATH%
- Open a Command Prompt
where user-token and api-token are the User Key and API Token/Key you recorded earlier, notification-title is the title of the notification and notification-text is the text
- Other supported methods for generating notifications include emailing an account specific email address and web services such as IFTTT
- Pushover allows 7,500 messages to be sent per application per month for free
- A maximum of ten devices can be linked to a single user account
- Device/computer names must be unique, or they will replace an existing device
- Internet access is required to send/receive notifications, although you will get any notifications which have been sent but not received when internet connectivity is restored (in my experience)
7 Command Line Utilities to Easily Send Email Using SMTP
Not only is email very useful for communication between friends and families and sending messages with attachments such as reports, photos, documents, presentations, video clips and music files, it’s also useful for notification purposes. For example, a website monitoring service such as Pingdom has alerts where you’ll be notified through different methods such as email, SMS, twitter or in-app when your server is down. Third party backup software also normally has at least an email notification feature where you can set it up to automatically email you when the backup process has completed or failed.
If you are writing a batch file and want to send an automated email when the batch has completed running or if you’re faced with a third party software that does not even support email notification, then the simple solution is to use a command line email sending tool for Windows. Here we have 7 ways to look at.
- sender@gmail.com = Replace it with your full Gmail address
- recipient@email.com = Replace it with the email address that will receive the message
- YourGmailPassword = Replace it with your Gmail password
- subject = The subject of the email. Make sure it is enclosed with double quotes if there are spaces. For example, “This is a long subject“
- body = The message of the email. Should also enclose with double quotes if there are spaces
1. SwithMail
Out of all the command line email sending tools, we’d consider SwithMail as one of the best in its class, if not the best. Instead of the need to write really long command line options to silently send an email where you might make mistakes and need a few tries to get it right, configuring SwithMail is quite foolproof thanks to the easy to use settings configuration GUI. You even test the email settings to make sure that it is able to successfully send an email.
Other than the standard options such as attachments, CC, BCC that you’d normally find when sending an email, SwithMail supports returning error codes, global variables and wildcard attachments which is very useful to automatically send log files with dated filenames. Below is a working example of SwithMail command line options to send an email using Gmail account.
SwithMail.exe /s /from sender@gmail.com /pass YourGmailPassword /server smtp.gmail.com /p 587 /SSL /to recipient@email.com /sub subject /b message
2. CMail
If you need to use a command line email sending tool that supports proxy, CMail would be your choice as it’s the only one that can support socks and HTTPS based proxy. Other interesting features that can be found in CMail are sending the whole directory content based on wildcard attachment and delivery status notification.
The full working command line to send an email using Gmail is as follows:
CMail.exe -secureport -host:sender@gmail.com:YourGmailPassword@smtp.gmail.com:465 -from:sender@gmail.com -to:recipient@email.com -subject:subject -body:message
3. SendSMTP
Running SendSMTP will bring up an interactive graphical user interface to send emails but at the same time it also supports command line instructions to silently send email with just one line of commands. Although an advanced user would have no problems with the command line arguments, a GUI will greatly help a basic computer user in creating a working config file.
Some notable features found in SendSMTP are the ability to save the password as encrypted using 128-bit Rijndael (AES) rather than saving the password as clear text, enable log file to save the activity of the SendSMTP program, and can return codes to report if the send email is successful (0), failed (1), or cannot find settings (2). The full command line for SendSMTP to send email using Gmail is as follow.
SendSMTP.exe /nos /host smtp.gmail.com /port 587 /auth 2 /userid sender@gmail.com /pass YourGmailPassword /from sender@gmail.com /to recipient@email.com /subject subject /body message
However, if you’ve saved the settings as default from the GUI which will create a SendSMTP.ini file at the same location as the program, a much shorter command line can be used to send an email.
Do note that there are 2 versions available on the download page. You will need the newer version with the bigger file size to support sending email using Gmail because the old version does not support SASL authentication.
4. mailsend
Comparing with the utilities mentioned above, mailsend is a simpler command line tool to send email using SMTP. It doesn’t have fancy features such as loading config from an external file, password encryption, GUI, error codes and etc. However, an interesting feature found in mailsend that is not available on other command line email sending tool is the ability to show SMTP server information by using the -info option.
mailsend is available for both Windows and Linux operating system. Below is the example command line for mailsend to send an email using Gmail.
mailsend1.17b15.exe -t recipient@email.com -f sender@gmail.com -ssl -port 465 -auth -smtp smtp.gmail.com -sub subject -M message -user sender@gmail.com -pass YourGmailPassword
5. Send-It-Quiet
Send-It-Quiet is the smallest command line SMTP mailer utility that weighs only 14KB in size and this is made possible with .NET Framework. This would also mean that you need to have .NET Framework 3.5 installed to run Send-It-Quiet. Send-It-Quiet only comes with very basic parameters that are enough to send an email. Possibly the only extra features found in Send-It-Quiet are the return value of ERRORLEVEL and also the flexibility of manually adding the parameters to registry.
The command line to send an email using Send-It-Quite with a Gmail account is:
senditquiet.exe -s smtp.gmail.com -port 587 -u sender@gmail.com -protocol ssl -p YourGmailPassword -f sender@gmail.com -t recipient@email.com -subject subject -body message
6. SendEmail
SendEmail is written in Perl but there is no need to install Perl in Windows for this command line mailer utility to work. SendEmail was last updated in 2009, but the last version has TLS support which means it can send email using Gmail SMTP. In terms of features, it is quite similar to Send-It-Quiet which only supports the standard email sending options such as to, from, subject, body, attachment, etc. SendEmail is available for both Windows and Linux operating systems.
Here is an example of the command line options that can send email using Gmail SMTP.
sendEmail.exe -o tls=yes -f sender@gmail.com -t recipient@email.com -s smtp.gmail.com:587 -xu sender@gmail.com -xp YourGmailPassword -u subject -m message
7. PowerShell
PowerShell is included in Windows operating systems since Windows 7 which means you can actually use a powershell script to send an email through Gmail SMTP without any of the command line tools mentioned above.
The sample script that can be downloaded at the link below is a very basic one that is meant to only send an email without attachment support. Simply download the ps1 script, open it with Notepad or Windows PowerShell ISE and change the credentials located at line number 8. The command line to run the powershell script is as follows. Make sure you update the path to the .ps1 file.
Powershell.exe -executionpolicy remotesigned -File C:\Users\Raymond\sendemail.ps1
The popular Blat is not included in the list because it does not support SSL which means it cannot send email using Gmail SMTP. Bmail (last updated in 2004), cmdsendmail which is a part of CommandLine Tools, and XmlSendmail are also example of command line send mail utility that doesn’t support SSL.