- How-to: Create and Run a CMD batch file
- Run a batch file
- View the startup command line
- Run a Powershell script
- Run a VBScript file
- How do you run a command as an administrator from the Windows command line?
- 8 Answers 8
- Caveat: Enable the admin account
- Useful Run Commands Every Windows User Should Know
- List of Run Commands
- More Run Commands
How-to: Create and Run a CMD batch file
To prepare a new batch script, save the file as plain ASCII text with the file extension .CMD
Run a batch file
A batch file can be run by double clicking it in Windows explorer, or by typing the name/path at the command line, optionally passing any parameters needed.
From the start menu: START > RUN c:\path_to_scripts\my_script.cmd , OK
If the filename includes any spaces, then you will need to surround the command with quotes:
«c:\path to scripts\my script.cmd «
Open a new CMD prompt by choosing START > RUN cmd , OK
From the command line, enter the name of the script and press return.
C:\Batch> Demo.cmd
or
C:\Batch> c:\path_to_scripts\my_script.cmd param1 param2
This can be made easier by creating a shortcut for the start menu or taskbar.
To run a batch file from within another batch file, use the CALL command, otherwise the first script will start the second script and immediately exit, so any further commands in the first script will not run.
It is also possible to run batch scripts with the old (Windows 95 style) .BAT extension, but be aware that these will run in 16 bit compatibility mode, and that sets the ERRORLEVEL according to the old MSDOS rules.
View the startup command line
The environment Variable %CmdCmdLine% will expand into the original command line passed to CMD.EXE
When a batch file is launched from the command line %CmdCmdLine% will return:
C:\WINDOWS\system32\cmd.exe param1
When a batch file is launched by double clicking in Windows Explorer or START > RUN, %CMDCMDLINE% will return:
C:\WINDOWS\system32\cmd.exe /c «»C:\demo\batch.cmd param1
The /c can be used to detect the start mode:
Echo %CmdCmdLine% | findstr /c:» /c » >nul && Echo Started with a double click.
Run a Powershell script
To run a PowerShell script from the CMD shell:
If the arguments need quotes you will need to triple them so they are escaped:
When calling PowerShell from CMD be aware that a comma is a CMD delimiter, this makes it impossible to pass an array of comma separated values to PowerShell. item1,item2,item3 is treated the same as item1 item2 item3
Run a VBScript file
To run a VBScript from the CMD shell:
“The method of the enterprising is to plan with audacity and execute with vigor”
How do you run a command as an administrator from the Windows command line?
I have a small script that performs the build and install process on Windows for a Bazaar repository I’m managing. I’m trying to run the script with elevated, administrative privileges from within the Windows shell (cmd.exe)—just as if I’d right-clicked it and chosen Run as Administrator, but without using any method that requires use of the graphical interface.
8 Answers 8
A batch/WSH hybrid is able to call ShellExecute to display the UAC elevation dialog.
Press the start button. In the search box type «cmd», then press Ctrl + Shift + Enter
All you have to do is use the runas command to run your program as Administrator (with a caveat).
In my case, this was
Note that you must use Quotation marks, else the runas command will gobble up the switch option to cmd.
Also note that the administrative shell (cmd.exe) starts up in the C:\Windows\System32 folder. This isn’t what I wanted, but it was easy enough to pass in the current path to my installer, and to reference it using an absolute path.
Caveat: Enable the admin account
Using runas this way requires the administrative account to be enabled, which is not the default on Windows 7 or Vista. However, here is a great tutorial on how to enable it, in three different ways:
I myself enabled it by opening Administrative Tools, Local Security Policy, then navigating to Local Policies\Security Options and changing the value of the Accounts: Administrative Account Status policy to Enabled, which is none of the three ways shown in the link.
Useful Run Commands Every Windows User Should Know
A quick-and-easy keyboard-only way to run Windows’ wealth of tools is through the “Run” command. If you know the corresponding Run command of a tool or task, then you know the quickest way to access said tool or task.
The following is a list of our favorite Run commands to help you be more productive.
Note: Press Win + R on your keyboard to open the Run dialog box, and enter any of the below commands to access the respective tool.
List of Run Commands
1. services.msc – When you enter “services.msc” and press the Enter button, it will open the Windows Services app where you can easily start, stop and configure other settings for each and every service individually. It’s quite helpful when you want to toggle a service.
2. mstsc – Entering “mstsc” into the Run dialog box opens the Remote Desktop Connection app which allows you to connect to another Windows computers over the local network or through the Internet. This helps you use the host computer as your own.
3. msinfo32 – If you want to quickly get your system information, then the “msinfo32” command is the way to go. At a glance it will display all the system details including the hardware resources and software environment.
4. sdclt – This command opens the Backup and Restore window that allows you to quickly set a backup schedule or restore any of your previous backups.
5. compmgmt.msc – The Computer Management app is where you can access almost all the advanced Windows modules like Event Viewer, Shared Folder, System Tools, etc.
6. cleanmgr – This command allows you to open the Windows Disk Cleanup utility. Once opened, simply select the drive your want to clean up and click the “OK” button.
7. eventvwr.msc – Windows Event Viewer is where Windows stores all the monitoring and troubleshooting messages. You can use this command to quickly access the Event Viewer application.
8. control – Every Windows user knows a thing or two about the Windows Control Panel, and using this command you can quickly access the Control Panel with some stumbling around.
9. mmc – Microsoft Management Console (MMC) is an advanced Windows module that is mainly aimed at system administrators and power users, as it sports all the tools required for configuring and monitoring a Windows system.
10. resmon – Whenever you want to check how your system resources are being utilized, simply use this Run command, and it displays everything from your CPU to Dist to Network.
11. \ – This is one of the lesser-known Run commands. Just enter the backslash into the Run dialog box, and it will open up the C drive. It is one of the quickest ways to access the C drive.
12. . – This is yet another lesser-known Run command. When executed, it opens the current user’s home folder which hosts all the other local folders like the Downloads, Documents, Desktop, Pictures, etc.
13. .. – When you execute these two dots in the Run dialog box, it will open up the Users folder which is located directly in the C drive.
14. calc – If you want to quickly open the built-in Windows calculator app, typing calc in the Run dialog box is the easiest way to do it.
15. cmd – Even Windows users have to deal with the command line sometimes. With this command you can quickly open the command prompt without administrator privileges.
16. powershell – If the command prompt is too old for you, then you may want to try PowerShell. Just type this command in the Run dialog box, and you will have your PowerShell opened without administrator privileges.
17. netplwiz – The general user accounts option is available through the Control Panel, but if you want to mess with the advanced user account options, then use this command to open the Advanced User Accounts window. If you want to deal with the Authorization Manager, then use the Run command azman.msc .
18. gpedit.msc – Group Policy Editor in Windows allows you to set and edit different Windows policies of a local or remote computer. Since Group Policy Editor is an advanced tool, it is buried deep inside Windows, and this Run command is the easiest way to access it.
19. lusrmgr.msc – Using this command, you can open the Local Users and Groups Manager where you can edit several properties of all the users and groups.
20. mrt – Every month Windows releases a newer version of Microsoft Windows Malicious Software Removal Tool through the Windows Update. This free tool helps you in cleaning some of the most popular malicious software from your Windows computer. This tool runs silently in the background, but if you want to run it manually, then use this Run command.
21. ncpa.cpl – Being an Internet user means that you have to deal with occasional (if not daily) network problems, and one way to troubleshoot your network connection is by accessing your Network Adapters. To access all your Network Adapters, you can use this Run command.
22. perfmon.msc – If you want to monitor the performance of your Windows computer and effects of the programs you run, running Performance Monitor will provide ample data. You can access the Performance Monitor using this command.
23. powercfg.cpl – Windows hosts a wide range of power options to deal with your computer’s power usage, and you can access all those Power Options using this command.
24. appwiz.cpl – Using this command you can quickly access the Programs and Features window where you can quickly uninstall your installed programs.
25. devmgmt.msc – Windows Device Manager is where you can manage all your hardware devices, and you can use this Run command to quickly access it. Alternatively, you can also use the command “hdwwiz.cpl.”
26. regedit – Regedit Run command can be used to access the Windows Registry, which is a hierarchical database that hosts all the configurations and settings of an operating system and the installed programs.
27. msconfig – Windows System Configuration is where you can edit different things like the boot options, startup options, services, etc. You can use this Run command to access the System Configuration window.
28. sysdm.cpl – If you ever want to access the System Properties window, then using this Run command opens it right up.
29. firewall.cpl – If you want to manage or configure your Windows firewall, then you can use this Run command to quickly access the Firewall window.
30. wuapp – Last but not least, you can use this command to check, manage and configure all your Windows update settings.
More Run Commands
Can’t get enough of the Run command? Here we have compiled a big list of all the Run commands available in Windows.
Task Name | Run Command |
---|---|
About Windows | winver |
Add a Device | devicepairingwizard |
Add Hardware Wizard | hdwwiz |
Advanced User Accounts | netplwiz |
Authorization Manager | azman |
Backup and Restore | sdclt |
Bluetooth File Transfer | fsquirt |
Calculator | calc |
Certificates | certmgr |
Change Computer Performance Settings | systempropertiesperformance |
Change Data Execution Prevention Settings | systempropertiesdataexecutionprevention |
Change Printer Settings | printui |
Character Map | charmap |
ClearType Tuner | cttune |
Color Management | colorcpl |
Command Prompt | cmd |
Component Services | comexp |
Component Services | dcomcnfg |
Computer Management | compmgmt |
Computer Management | compmgmtlauncher |
Connect to a Network Projector | netproj |
Connect to a Projector | displayswitch |
Control Panel | control |
Create A Shared Folder Wizard | shrpubw |
Create a System Repair Disc | recdisc |
Credential Backup and Restore Wizard | credwiz |
Data Execution Prevention | systempropertiesdataexecutionprevention |
Default Location | locationnotifications |
Device Manager | devmgmt |
Device Pairing Wizard | devicepairingwizard |
Diagnostics Troubleshooting Wizard | msdt |
Digitizer Calibration Tool | tabcal |
DirectX Diagnostic Tool | dxdiag |
Disk Cleanup | cleanmgr |
Disk Defragmenter | dfrgui |
Disk Management | diskmgmt |
Display | dpiscaling |
Display Color Calibration | dccw |
Display Switch | displayswitch |
DPAPI Key Migration Wizard | dpapimig |
Driver Verifier Manager | verifier |
Ease of Access Center | utilman |
Encrypting File System Wizard | rekeywiz |
Event Viewer | eventvwr |
Fax Cover Page Editor | fxscover |
File Signature Verification | sigverif |
Getting Started | gettingstarted |
IExpress Wizard | iexpress |
Import to Windows Contacts | wabmig* |
iSCSI Initiator Configuration Tool | iscsicpl |
iSCSI Initiator Properties | iscsicpl |
Language Pack Installer | lpksetup |
Local Group Policy Editor | gpedit |
Local Security Policy | secpol |
Local Users and Groups | lusrmgr |
Location Activity | locationnotifications |
Magnifier | magnify |
Malicious Software Removal Tool | mrt |
Manage Your File Encryption Certificates | rekeywiz |
Math Input Panel | mip* |
Microsoft Management Console | mmc |
Microsoft Support Diagnostic Tool | msdt |
NAP Client Configuration | napclcfg |
Narrator | narrator |
New Scan Wizard | wiaacmgr |
Notepad | notepad |
ODBC Data Source Administrator | odbcad32 |
ODBC Driver Configuration | odbcconf |
On-Screen Keyboard | osk |
Paint | mspaint |
Performance Monitor | perfmon |
Performance Options | systempropertiesperformance |
Phone Dialer | dialer |
Presentation Settings | presentationsettings |
Print Management | printmanagement |
Printer Migration | printbrmui |
Printer User Interface | printui |
Private Character Editor | eudcedit |
Problem Steps Recorder | psr |
Protected Content Migration | dpapimig |
Registry Editor | regedit |
Remote Access Phonebook | rasphone |
Remote Desktop Connection | mstsc |
Resource Monitor | resmon |
Resultant Set of Policy | rsop |
Securing the Windows Account Database | syskey |
Services | services |
Set Program Access and Computer Defaults | computerdefaults |
Share Creation Wizard | shrpubw |
Shared Folders | fsmgmt |
Snipping Tool | snippingtool |
Sound Recorder | soundrecorder |
SQL Server Client Network Utility | cliconfg |
Sticky Notes | stikynot |
Stored User Names and Passwords | credwiz |
Sync Center | mobsync |
System Configuration | msconfig |
System Configuration Editor | sysedit (This command doesn’t work in the 64-bit version of Windows.) |
System Information | msinfo32 |
System Properties (Advanced Tab) | systempropertiesadvanced |
System Properties (Computer Name Tab) | systempropertiescomputername |
System Properties (Hardware Tab) | systempropertieshardware |
System Properties (Remote Tab) | systempropertiesremote |
System Properties (System Protection Tab) | systempropertiesprotection |
System Restore | rstrui |
Tablet PC Input Panel | tabtip* |
Task Manager | taskmgr |
Task Scheduler | taskschd |
Trusted Platform Module (TPM) Management | tpm |
User Account Control Settings | useraccountcontrolsettings |
Utility Manager | utilman |
Version Reporter Applet | winver |
Volume Mixer | sndvol |
Windows Activation Client | slui |
Windows Anytime Upgrade Results | windowsanytimeupgraderesults |
Windows Contacts | wab* |
Windows Disc Image Burning Tool | isoburn |
Windows DVD Maker | dvdmaker* |
Windows Easy Transfer | migwiz* |
Windows Explorer | explorer |
Windows Fax and Scan | wfs |
Windows Features | optionalfeatures |
Windows Firewall with Advanced Security | wf |
Windows Help and Support | winhlp32 |
Windows Journal | journal* |
Windows Media Player | wmplayer* |
Windows Memory Diagnostic Scheduler | mdsched |
Windows Mobility Center | mblctr |
Windows Picture Acquisition Wizard | wiaacmgr |
Windows PowerShell | powershell* |
Windows PowerShell ISE | powershell_ise* |
Windows Remote Assistance | msra |
Windows Repair Disc | recdisc |
Windows Script Host | wscript |
Windows Update | wuapp |
Windows Update Standalone Installer | wusa |
WMI Management | wmimgmt |
WMI Tester | wbemtest |
WordPad | write |
XPS Viewer | xpsrchvw |
Access Screen Resolution page | desk.cpl |
Access Mouse properties | main.cpl |
Access Windows Action Center | wscui.cpl |
Access Network Adapters | ncpa.cpl |
Access Power Option | powercfg.cpl |
Access the Programs and Features Window | appwiz.cpl |
Access the System Properties | sysdm.cpl |
Access the Windows Firewall | firewall.cpl |
*You cannot run these commands from a command prompt or the search box. |
As you can see, the Windows Run command is one of the best utilities you can find in Windows. Besides the commands shared above that first come to mind, there are many other commands to access different parts of Windows. So if you think that we missed any of your favorite Run commands, do share them in the comments below.