Windows service recovery restart

Recovery options in Windows 10

If you’re having problems with your PC, the following table can help you decide which recovery option to use.

See this section

Your PC isn’t working well and you recently installed an update.

Your PC isn’t working well and it’s been a while since you installed an app, driver, or update.

Your PC won’t start, you haven’t created a recovery drive, and resetting your PC didn’t work.

Your PC won’t start and you haven’t created a recovery drive.

Your PC won’t start and you’ve created a recovery drive.

You want to reinstall your previous operating system.

Your PC isn’t working well and you recently installed an app.

Click one of the recovery options below and follow the steps to try to get things working again.

If you’ve recently installed a Windows update, uninstall the update to try to resolve the issue.

Select the Start button, then select Settings > Update & Security > Windows Update > View your update history > Uninstall updates.
View update history settings

Right-click the update you want to remove, and then select Uninstall.

Important: If you’ve encrypted your device, you’ll need your BitLocker key to reset your PC If you don’t know your BitLocker key, see Find my BitLocker recovery key.

Resetting reinstalls Windows 10, but lets you choose whether to keep your files or remove them, and then reinstalls Windows. You can reset your PC from Settings, the sign-in screen, or by using a recovery drive or installation media.

Reset your PC from Settings

Select the Start button, then select Settings > Update & Security > Recovery .
Open Recovery settings

Under Reset this PC, select Get started and then choose from the options and/or settings in the table below.

Keep my files > Change settings > Preinstalled apps On

Reinstalls Windows 10 and keeps your personal files.

Removes apps and drivers you installed.

Removes changes you made to settings.

Restores any apps your PC manufacturer installed if your PC came with Windows 10.

Keep my files > Change settings > Preinstalled apps Off

Reinstalls Windows 10 and keeps your personal files.

Removes apps and drivers you installed.

Removes changes you made to settings.

Removes any apps your PC manufacturer installed.

Reinstalls Windows 10 and removes your personal files.

Removes apps and drivers you installed.

Removes changes you made to settings.

Removes any apps your PC manufacturer installed. (If your PC came with Windows 10, apps from your PC manufacturer will be reinstalled.)

Note: Remove everything > Change settings gives you two options.

Data erasure On removes files and cleans the drive. If you’re planning to donate, recycle, or sell your PC, use this option. This might take an hour or two, but it makes it harder for other people to recover files you’ve removed.

Data erasure Off just removes files. It takes less time, but is less secure.

Reset your PC from the sign-in screen

If you can’t open Settings, you can reset your PC from the sign-in screen. Here’s how:

Press Windows logo key + L to get to the sign-in screen, and then restart your PC by pressing the Shift key while you select the Power button > Restart in the lower-right corner of the screen.

Your PC will restart in the Windows Recovery Environment (WinRE) environment.

On the Choose an option screen, select Troubleshoot > Reset this PC, and then choose one of the options in the previous table.

Connect the installation media you created to your PC and reinstall Windows 10.

Open File Explorer and select the drive with the installation media.

From the root directory of the drive, double-click setup.exe, and then select Yes when asked if you’d like to allow the app to make changes to your device.

Select Change what to keep.

Select one of the following options, and then select Next:

Keep personal files and apps – This will preserve your personal data, apps, and settings.

Keep personal files only – This will preserve your personal data and settings, but all your apps will be removed.

Keep nothing – This will remove all personal data, settings, and apps.

Warning: You cannot undo a reinstallation of Windows 10. Be sure to back up your files first if you choose the Keep nothing option.

To finish, select Install to start reinstalling Windows 10 on your PC.

Your PC will restart several times during the resinstallation.

Important: If you’ve encrypted your device, you’ll need your BitLocker key to use a recovery drive to restore or reset your PC If you don’t know your BitLocker key, see Find my BitLocker recovery key.

If your PC won’t start and you haven’t created a recovery drive, download installation media and use it to restore from a system restore point or reset your PC.

Download the Windows 10 media creation tool and then run it.

Select Create installation media for another PC.

Choose a language, edition, and architecture (64-bit or 32-bit).

Читайте также:  Не помню текущий пароль windows

Follow the steps to create installation media, and then select Finish.

Connect the installation media you created to your nonfunctional PC, and then turn it on.

On the initial setup screen, enter your language and other preferences, and then select Next. If you don’t see the setup screen, your PC might not be set up to boot from a drive. Check your PC manufacturer’s website for info on how to change your PC’s boot order, and then try again.

Select Repair your computer.

On the Choose an option screen, select Troubleshoot. From there, you can:

Restore from a system restore point by selecting Advanced options > System Restore. This will remove recently installed apps, drivers, and updates that might be causing your PC problems. Restoring from a restore point won’t affect your personal files.

Important: If you’ve encrypted your device, you’ll need your BitLocker key to use a recovery drive to restore or reset your PC If you don’t know your BitLocker key, see Find my BitLocker recovery key.

If your PC won’t start, you can use a recovery drive to restore from a system restore point or recover your PC. For info on how to create a recovery drive on a working PC, see Create a recovery drive.

Note: If you are using a Surface, see Creating and using a USB recovery drive for Surface to download and create a USB recovery image specifically for your Surface device.

To restore or recover using the recovery drive:

Connect the recovery drive and turn on your PC.

Press Windows logo key + L to get to the sign-in screen, and then restart your PC by pressing the Shift key while you select the Power button> Restart in the lower-right corner of the screen.

Your PC will restart in the Windows Recovery Environment (WinRE) environment.

On the Choose an option screen, select Troubleshoot, and then select one of the following two options. (If you don’t see the Choose your option screen, your PC might not be set up to boot from a drive. Check your PC manufacturer’s website for info on how to change your PC’s boot order.)

To restore from a system restore point, select Advanced Options > System Restore. This won’t affect your personal files, but it will remove recently installed apps, drivers, and updates that might be causing your PC problems.

To reinstall Windows 10, select Advanced Options > Recover from a drive. This will remove your personal files, apps and drivers you installed, and changes you made to settings.

For a limited time after upgrading to Windows 10, you’ll be able to go back to your previous version of Windows by selecting the Start button, then select Settings > Update & Security > Recovery and then selecting Get started under Go back to the previous version of Windows 10. This will keep your personal files, but it’ll remove apps and drivers installed after the upgrade, as well as any changes you made to settings. In most cases, you’ll have 10 days to go back.
Open Recovery settings

To go back, you’ll need to:

Keep everything in the windows.old and $windows.

bt folders after the upgrade.

Remove any user accounts you added after the upgrade.

Know the password you used to sign in to Windows 7 or Windows 8.1 (if you used one).

Have the USB drive you used to upgrade to Windows 10 (if you used one).

Note: If you go back to Windows 8.1, some apps that came with Windows, like Mail and People, might not work anymore. To fix the apps, reinstall them from the Microsoft Store.

Note: The option in Settings to go back to your previous version of Windows is only available for a limited time after upgrading.

Info for Windows Insiders

If you’re an Insider and the current preview build isn’t working for you, select the Start button, then select Settings > Update & Security > Recovery . Under Go back to the previous version of Windows 10, select Get Started. This won’t remove your personal files, but it’ll remove recently installed apps and drivers, and change settings back to their defaults.

Going back to an earlier build won’t remove you from the Insider Program. When the next preview build is ready, it’ll be installed on your PC.

This option takes your PC back to an earlier point in time, called a system restore point. Restore points are generated when you install a new app or driver, and when you create a restore point manually. Restoring won’t affect your personal files, but it will remove apps, drivers, and updates installed after the restore point was made.

In the search box on the taskbar, type control panel,andthen choose it from the list of results

In the Control Panel search box, type recovery.

Select Recovery > Open System Restore.

In the Restore system files and setting box, select Next.

Select the restore point that you want to use in the list of results, and then select Scan for affected programs.

If you don’t see the restore point that you want to use, select the Show more restore points check box to see more restore points.

Читайте также:  Windows горячие клавиши таблица

If you’re not seeing any restore points, it might be because system protection isn’t turned on. Here’s how to check:

In the search box on the taskbar, type control panel,andthen choose it from the list of results.

In the Control Panel search box, type recovery.

Select Recovery > Configure System Restore > Configure and see if the Turn on system protection option is selected.

If the Turn on system protection option is not selected, system protection isn’t turned on and there aren’t any restore points. In this scenario, you won’t be able to recovery your PC using a system restore point and will need to use one of the other recovery options listed on this page.

If the Turn on system protection option is selected, continue with step 6.

You’ll see a list of items that will be deleted if you remove this restore point. If you’re OK with the deletions, select Close> Next > Finish.

Windows service recovery restart

You could have a look at the blog post below, see if it helps you!

» First failure: what should occur the first time the service fails. Valid options are «Take No Action», «Restart the Service», «Run a Program», and «Restart the Computer».

Second failure: same options the second time a service fails

Subsequent failures: same options for any subsequent failure

Reset fail count after: the number of days the service must be running before the failure count is reset

Restart service after: the amount of time in minutes to wait to restart the service

This is very nice, but it is very easy to misunderstand what these values actually do. I have seen a number of services (and I tried this myself) set these values to 0 days and 0 minutes. The problem is your service will continually restart if you set the failure count to reset after 0 days, if the service at least started correctly. The result is only the first option («first failure») will ever be run.

To fix this, set the failure count to reset after one day. The drawback to this approach is your service may stay stopped after failing several times but this likely means something is toast anyways.

One thing also to take into account is not all services will work with the reset logic — or in other words just setting the recovery options on any service does not guarantee that it will restart. In order for the service to restart, it must exit abnormally. This generally means the service must exist with a non-zero exit code and the service status must not be stopped (note: this has changed for Vista — it is possible to set the service status to stopped and provide an exit code to trigger the restart logic).

Old Dog, New Tricks

Striving for better ways to write code

Using the Automatic Recovery Features of Windows Services

Windows Services support the ability to automatically perform some defined action in response to a failure. The recovery action is specified in the Recovery tab of the service property page (which can be found in Settings->Control Panel->Administrative Tools -> Services). The Recovery tab allows you to define actions that can be performed on the 1st failure, 2nd failure, and subsequent failures, and also provides support for resetting the failure counters and how long to wait before taking the action. The allowed actions are

  • Take No Action (default)
  • Restart the Service
  • Run a Program
  • Restart the Computer

Having this type of functionality is really helpful from the perspective of a developer of services. Who wants to re-invent the wheel and have to write recovery code in the service if you can get it for free. Plus it allows the recovery to be reconfigured as an IT task as opposed to rebuilding the software. I did discover a few gotchas along the way, though.

Building a Basic Service
Let’s start with the basics though. You can create a service using Visual Studio by adding a project and selecting the type “Windows Service”. This will populate an empty service. First thing I like to do is give the classes and service real names. In this case I am testing that the recovery from a failure works so I renamed my class to FailingService.cs (not something I would recommend calling a product, but in this case it fits) . I also changed the ServiceName using the Properties of the window from Service1 (the default) to TestFailingService. This is the name that is going to appear in the Windows Services dialog, so I strongly recommend changing it.

You will also want to add an installer for your service as this will make it much easier to install the service onto your computer. You can’t run the service like a regular EXE file, so you definitely want an installer here.

Now that we’ve done all the basics, you should be able to build your service and install it. You can install the service using the InstallUtil.exe program that comes with the .NET Framework. Open a Visual Studio Command Prompt (this will already have a path to InstallUtil) and run

Note: If there are spaces in the path you should enclose the path in “” as in InstallUtil “C:Documents and SettingsuserMy DocumentsVisual Studio 2005ProjectsServiceRecoveryTestsTestServicebinDebugTestService.exe”

Читайте также:  Google drive как локальный диск linux

Depending on how your PC is configured, you may be prompted to log in as part of installing the service. If you are on a domain you should use the full user name of domainuser.

From the Services tab you should now be able to start and stop your service. You should also be able to go to the Windows Event Viewer and see events related to starting and stopping your service in the Application and System logs.

To uninstall the service use the commands above, but with the /u option, as in

Error Recovery
What I really wanted to do was to work with the failure recovery features of the service, so the first thing I did was create a thread that would simulate an error on some background processing of the service. The thread sleeps for 30 seconds and then throws an exception.

Since this exception is being thrown on a different thread than the main thread, I need to subscribe to the AppDomain’s UnhandledException event. If I don’t do this the thread will just die silently and the service will continue to run, which is not what I want.

Initially I thought I could just take advantage of the ServiceBase class ExitCode property. I figured that if I set the ExitCode property to a non-zero value and stopped the service that would be interpreted as a failure and the service would automatically be restarted, as in

That is not the case though as I found out here. “A service is considered failed when it terminates without reporting a status of SERVICE_STOPPED to the service controller.”

So from this definition I decided that I needed to throw an exception in the Stop event handler, otherwise Stop would return normally, and it would not be considered a failure by the SCM.What I finally ended up doing was having the unhandled exception handler cache the unhandled exception and call Stop. The Stop event handler then checks if there is an unhandled exception and wraps that in an exception and throws it. Wrapping the exception, and passing the asynchronous exception as the InnerException, preserves the call stack of the asynchronous exception.

Examining the Event Viewer
I configured the service to restart after the 1st and 2nd failures, but to take no action after the third. The fail counters will reset after 1 day and the service will restart immediately after a failure.

The service is written to fail after 30 seconds and the recovery mechanism should restart it immediately. If you start the log file you should see entries in the Event Viewer’s Application or System log showing the service starting, failing, and restarting.

You can also get more information by opening up some of these events, such as service state transitions, how many times the error has occurred, or detailed error messages. Here is an example

Resetting the Error Counters
Unfortunately the Reset fail count after and Restart service after fields in the Recovery tab only takes integers. It would have been nice to be able to have granularity less than a whole day for the reset of the counters to take effect. If you are running this service repeatedly (like I was doing during testing) the counters may be too high to automatically restart the service. If you expected a restart and didn’t get one, examine the entries in the Event Viewer’s System log and you should see something like this

If you want to reset the counters you can set the Reset fail count after field to zero which will cause the counters to reset after each failure.

Turning Off the JIT Debugger
One of the main reasons you write a service is to do something without user intervention (or even with a user logged in). One of the problems with this implementation is that you end up throwing an unhandled exception, by design, from the Stop event handler. If the Microsoft Just-In-Time (JIT) debugger is configured to run on your system it will prompt you if you want to debug the application. For a service that you want to auto-recover this is a really bad thing, since….well there might not be anyone there to answer the prompt.

I found a few tips on how to turn this off. You can read about them here.

Note: If you have multiple versions of Visual Studio installed (I have 2005 and 2003 installed) you have to turn off the JIT debugger for each version.

Service Source Code
Here is the source code for the service. The service is designed to fail after 30 seconds to test the recovery mechanisms of the Windows services. The code automatically generated for the installer was not modified at all, except to change the service name which was described above.

Programmatically Configuring Recovery
The installers do not provide any support for programmatically setting up the recovery actions, which I find a little frustrating. I did find some code here that will allow you to do this, but have not had a chance to test it out or incorporate it into the sample.

Оцените статью