- Reboot Windows computer from command line (CMD)
- Command to reboot windows computer
- To shutdown a Windows computer
- To abort computer reboot
- To force reboot by closing applications without warning
- Add reason for the reboot of the computer
- Reboot windows using WMIC
- How to Open Command Prompt
- Open Command Prompt to Execute Commands in Windows 10, 8, 7, Vista, & XP
- Open Command Prompt in Windows 10
- Open Command Prompt Through the Start Menu
- Open Command Prompt Using Power User Menu
- Open Command Prompt in Windows 8 or 8.1
- Open Command Prompt in Windows 7, Vista, or XP
- Other Ways to Open Command Prompt
- Elevated Command Prompts and Old Windows Versions
- How to restart service using command prompt?
- 7 Answers 7
- Is there a command to refresh environment variables from the command prompt in Windows?
- 24 Answers 24
Reboot Windows computer from command line (CMD)
We can reboot a Windows computer from command line using the in-built shutdown command.В Below you can find syntax of this command for various use cases. The below commands work on Windows 7, Windows 8, Windows 10 and all other server editions.
Command to reboot windows computer
The above command will set a time out of 30 seconds to close the applications. After 30 seconds, windows reboot will start.
If you want to reboot Windows with your own time out value you can use the below command.
To shutdown a Windows computer
To abort computer reboot
If you have issued a reboot command and have changed mind, you can stop Windows reboot by running the below command.
When you run this, you would see a pop up window at the right bottom part of the screen(near system tray) that shows the message “The scheduled shutdown has been cancelled”.
To force reboot by closing applications without warning
Open the shutdown GUI
Add reason for the reboot of the computer
Reboot Windows using WMIC commands:
Reboot windows using WMIC
You can run the below wmic command to reboot Windows OS.
Is the abort command supposed to work if one has issued the reboot from GUI. I have tried this on my Windows 7 Ultimate, it does not seem to be working. it says ‘no shutdown was in progress’
Abort works only when you had issued the reboot/shutdown using the command. GUI actions are not aborted by /a option.
I’ve just attempted all commands from Windows 7 Ultimate install disk (used as recovery disk) and I obviously have a fault with my disk trying to load the Windows installation volume, I’ve launched command prompt via shift F10 as the GUI was not responding or should I say it had a never ending hour glass, trying a force shut down resulted in ‘the function is unknown’ proceeded with some numerical digits inside of closed brackets?
Shutdown /a is very handy when windows update tries to force reboot your computer. You can run this command and cancel the reboot if you don’t want the reboot to happen at that time.
How to Open Command Prompt
Open Command Prompt to Execute Commands in Windows 10, 8, 7, Vista, & XP
Some popular Command Prompt commands you might have heard of include ping, netstat, tracert, shutdown, and attrib, but there are many more. We have a complete list here.
While Command Prompt probably isn’t a tool most of you will use on a regular basis, it can really come in handy now and then, maybe to troubleshoot a specific Windows problem or to automate some kind of task.
How you open Command Prompt differs between Windows versions, so you’ll find steps below for Windows 10, Windows 8 or Windows 8.1, and Windows 7, Windows Vista, and Windows XP. See What Version of Windows Do I Have? if you’re not sure.
Open Command Prompt in Windows 10
Select the Start button.
Type cmd.
Select Command Prompt from the list.
Open Command Prompt Through the Start Menu
Another way to open Command Prompt in Windows 10 is to look in its Start menu folder:
Select the Start button.
Select the Windows System folder from the list.
Choose Command Prompt from the folder group.
Open Command Prompt Using Power User Menu
One more method in Windows 10 is through the Power User Menu. If you’re using a keyboard or mouse, choose Command Prompt from the menu that appears after pressing Win+X or right-clicking the Start button.
You might see Windows PowerShell options in the Power User Menu instead of Command Prompt. In more recent versions of Windows 10, Command Prompt has been replaced by PowerShell, but you can still access it from the Power User Menu by editing the taskbar settings.
Open Command Prompt in Windows 8 or 8.1
Select the Start button and then swipe up to show the Apps screen. You can accomplish the same thing with a mouse by selecting the down arrow icon at the bottom of the screen.
Prior to the Windows 8.1 update, the Apps screen can be accessed from the Start screen by swiping up from the bottom of the screen, or right-clicking anywhere, and then choosing All apps.
If you’re using a keyboard or mouse, a really quick way to open a Command Prompt window in Windows 8 is through the Power User Menu—just hold the WIN and X keys down together, or right-click the Start button, and choose Command Prompt.
Swipe or scroll to the right on the Apps screen to locate the Windows System section heading.
Select Command Prompt. You can now execute whatever command you needed to run.
See our List of Windows 8 Command Prompt Commands for a complete list of the commands available through Command Prompt in Windows 8, including short descriptions and links to more in-depth information if we have it.
Open Command Prompt in Windows 7, Vista, or XP
Open the Start menu from the bottom-left corner of the screen.
In Windows 7 and Windows Vista, it’s a bit faster to enter command in the search box at the bottom of the Start menu and then choose Command Prompt when it appears in the results.
Go to All Programs > Accessories.
Choose Command Prompt from the list of programs.
Here’s our List of Windows 7 Commands and List of Windows XP Commands if you need a command reference for any of those versions of Windows.
Other Ways to Open Command Prompt
Command Prompt in Windows XP through Windows 10 can also be opened with a command. This is especially helpful if you like using the Run dialog box or if Windows Explorer has crashed and the Start menu is inaccessible (and thus the directions above don’t work).
To do this, enter cmd into the command-line interface. This can be in the Run dialog box (WIN+R) or Task Manager’s File > Run new task menu.
Elevated Command Prompts and Old Windows Versions
In versions of Windows released before Windows XP, like Windows 98 and Windows 95, Command Prompt doesn’t exist. However, the older and very similar MS-DOS Prompt does. This program is located in the Start menu and can be opened with the command run command.
Some commands, like the sfc command that’s used to repair Windows files, require that Command Prompt be opened as an administrator before they can be executed. You’ll know if this is the case if you get a message like one of these after trying to execute the command:
- check that you have administrative rights
- . command can only be executed from an elevated command prompt
- you must be an administrator
See How to Open an Elevated Command Prompt for help starting Command Prompt as an administrator, a process that’s a bit more complicated than what’s outlined above.
How to restart service using command prompt?
I want to restart Windows service using command prompt in [Icons] section using Inno Setup. Please help me to solve the problem.
7 Answers 7
You can use sc start [service] to start a service and sc stop [service] to stop it. With some services net start [service] is doing the same.
But if you want to use it in the same batch, be aware that sc stop won’t wait for the service to be stopped. In this case you have to use net stop [service] followed by net start [service] . This will be executed synchronously.
You could create a .bat-file with following content:
To restart a running service:
However, if you don’t know if the service is running in the first place and want to restart or start it, use this:
This works if the service is already running or not.
For reference, here is the documentation on conditional processing symbols.
This is my code, to start/stop a Windows service using SC command. If the service fails to start/stop, it will print a log info. You can try it by Inno Setup.
You can start and stop and query services using the SC command. As for innosetup i’m not sure.
PowerShell features a Restart-Service cmdlet, which either starts or restarts the service as appropriate.
The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service. If a service was already stopped, it is started without notifying you of an error.
You can specify the services by their service names or display names, or you can use the InputObject parameter to pass an object that represents each service that you want to restart.
It is a little more foolproof than running two separate commands.
The easiest way to use it just pass either the service name or the display name directly:
It can be used directly from the standard cmd prompt with a command like:
Is there a command to refresh environment variables from the command prompt in Windows?
If I modify or add an environment variable I have to restart the command prompt. Is there a command I could execute that would do this without restarting CMD?
24 Answers 24
You can capture the system environment variables with a vbs script, but you need a bat script to actually change the current environment variables, so this is a combined solution.
Create a file named resetvars.vbs containing this code, and save it on the path:
create another file name resetvars.bat containing this code, same location:
When you want to refresh the environment variables, just run resetvars.bat
The two main problems I had coming up with this solution were
a. I couldn’t find a straightforward way to export environment variables from a vbs script back to the command prompt, and
b. the PATH environment variable is a concatenation of the user and the system PATH variables.
I’m not sure what the general rule is for conflicting variables between user and system, so I elected to make user override system, except in the PATH variable which is handled specifically.
I use the weird vbs+bat+temporary bat mechanism to work around the problem of exporting variables from vbs.
Note: this script does not delete variables.
This can probably be improved.
ADDED
If you need to export the environment from one cmd window to another, use this script (let’s call it exportvars.vbs ):
Run exportvars.vbs in the window you want to export from, then switch to the window you want to export to, and type:
On Windows 7/8/10, you can install Chocolatey, which has a script for this built-in.
After installing Chocolatey, just type refreshenv .
Here is what Chocolatey uses.
By design there isn’t a built in mechanism for Windows to propagate an environment variable add/change/remove to an already running cmd.exe, either from another cmd.exe or from «My Computer -> Properties ->Advanced Settings -> Environment Variables».
If you modify or add a new environment variable outside of the scope of an existing open command prompt you either need to restart the command prompt, or, manually add using SET in the existing command prompt.
The latest accepted answer shows a partial work-around by manually refreshing all the environment variables in a script. The script handles the use case of changing environment variables globally in «My Computer. Environment Variables», but if an environment variable is changed in one cmd.exe the script will not propagate it to another running cmd.exe.
I came across this answer before eventually finding an easier solution.
Simply restart explorer.exe in Task Manager.
I didn’t test, but you may also need to reopen you command prompt.
Credit to Timo Huovinen here: Node not recognized although successfully installed (if this helped you, please go give this man’s comment credit).
This works on windows 7: SET PATH=%PATH%;C:\CmdShortcuts
tested by typing echo %PATH% and it worked, fine. also set if you open a new cmd, no need for those pesky reboots any more 🙂
Use «setx» and restart cmd prompt
There is a command line tool named «setx» for this job. It’s for reading and writing env variables. The variables persist after the command window has been closed.
It «Creates or modifies environment variables in the user or system environment, without requiring programming or scripting. The setx command also retrieves the values of registry keys and writes them to text files.»
Note: variables created or modified by this tool will be available in future command windows but not in the current CMD.exe command window. So, you have to restart.
If setx is missing:
Or modify the registry
To programmatically add or modify system environment variables, add them to the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment registry key, then broadcast a WM_SETTINGCHANGE message with lParam set to the string «Environment«.
This allows applications, such as the shell, to pick up your updates.
Calling this function has worked for me:
The best method I came up with was to just do a Registry query. Here is my example.
In my example I did an install using a Batch file that added new environment variables. I needed to do things with this as soon as the install was complete, but was unable to spawn a new process with those new variables. I tested spawning another explorer window and called back to cmd.exe and this worked but on Vista and Windows 7, Explorer only runs as a single instance and normally as the person logged in. This would fail with automation since I need my admin creds to do things regardless of running from local system or as an administrator on the box. The limitation to this is that it does not handle things like path, this only worked on simple enviroment variables. This allowed me to use a batch to get over to a directory (with spaces) and copy in files run .exes and etc. This was written today from may resources on stackoverflow.com
Orginal Batch calls to new Batch:
testenvget.cmd SDROOT (or whatever the variable)
Also there is another method that I came up with from various different ideas. Please see below. This basically will get the newest path variable from the registry however, this will cause a number of issues beacuse the registry query is going to give variables in itself, that means everywhere there is a variable this will not work, so to combat this issue I basically double up the path. Very nasty. The more perfered method would be to do: Set Path=%Path%;C:\Program Files\Software. \
Regardless here is the new batch file, please use caution.