Jump to content
Amaroq_Starwind

DISM / SFC in the background

Recommended Posts

I'm looking to create a scheduled task, PowerShell script, or command executable that would automatically run the commands DISM /online /cleanup-image /restorehealth and sfc /scannow in the background, and specifically in that order, both on startup and on a regular schedule, and most importantly without requiring a prompt for user input or requiring a UAC prompt. However, as I am not experienced with the task scheduler or with PowerShell, and I've never created a command executable before, I don't have the first clue how actually go about creating what I'm looking for. Could I have some help?

Share this post


Link to post
Share on other sites

The question is WHY?

Normally one might only run such a command or set of commands maybe once or twice in the life of the computer. Running it over and over would not seem to serve much real purpose.

 

Share this post


Link to post
Share on other sites

I have a mix of reasons.

For starters, it's Windows 10 running on an old laptop, and Windows Update has never been the most reliable for me. Also, I have an old hard-disk that isn't doing too well, and I'm paranoid about file corruption, but until I can afford an SSD to replace it (or better yet, a new computer entirely) I need to make do with what I have and make sure that the system integrity is always as close to intact as possible. I often encounter random issues on my computers that don't seem to have any discernible root cause, which I have begun to attribute to gremlins. That, and having a sort of "self-healing" thing already in place in the event of future errors occurring somewhere down the line just seems like it would be a smart idea.

This isn't a proper long-term fix or treatment plan so much as a stopgap solution to extend the life and usability of my system a little longer, albeit also having elements of being a bit of an experiment where I actually put an idea I have to the test. In this case, having a continuous version of DISM / SFC running was inspired by the self-healing capabilities of ReFS, along with the frequent risk of filesystem corruption caused by various other factors.

I do have both Windows Defender and MalwareBytes set up to protect my system from threats, but the one enemy they can never truly defend against is entropy itself.

On a semi-unrelated note, once I know how to create a script such as this, I can also set it up on my grandparents' computer to make their lives just a little bit more reliable, since I will often have to go over there to fix problems that unexpectedly develop for a variety of reasons.

Share this post


Link to post
Share on other sites

If you have an old hard drive that you believe is failing (can be tested) then causing any type of automated process that reads/writes to the drive is going to cause more stress and cause failure sooner.

Creating a task is easy. I just don't think it's prudent to run that often. I'll help you with it though a little later today. I have to run and go help someone else with something else right now.

 

Share this post


Link to post
Share on other sites
1 hour ago, Amaroq_Starwind said:

Also, I have an old hard-disk that isn't doing too well, and I'm paranoid about file corruption, but until I can afford an SSD to replace it (or better yet, a new computer entirely)

This sounds familiar, now I remember.... I recommended in one of your other topics to replace the hard drive, all the work your putting into that hard drive is really a waste of time since its failing... :rolleyes:

Share this post


Link to post
Share on other sites

Again, if the hard drive is failing, then running malware scans, automation routines, SFC, DISM are going to put undue stress on the hard drive and cause it to really fail even sooner. I would not recommend doing what you're asking to do.

That said. I was going to create the task for you, but it would actually be better to learn how to do on your own. The following links are pretty good links to show you how to do it on your own. Just takes some time to read and practice to gain experience. 

Creating a Scheduled Task in Windows 10
https://www.technipages.com/scheduled-task-windows


Microsoft article on command line Scheduled Task creation: Schtasks.exe
https://docs.microsoft.com/en-us/windows/desktop/taskschd/schtasks

Main Article from Microsoft
https://docs.microsoft.com/en-us/windows/desktop/taskschd/task-scheduler-start-page

Rob van der Woude's Scripting Pages
(follow along on this guys pages and you'll learn quite a bit about automating things in Windows)
SCHTASKS
Command line front-end for Windows' Task Scheduler
https://www.robvanderwoude.com/schtasks.php

 

Share this post


Link to post
Share on other sites

The GUI version of the Task Scheduler really needs a "Run Minimized" checkbox when setting an action to run a program. As for DISM and SFC, the main issue I have is setting the latter to only run when the former has finished successfully. Thank you for the materials, I'll come back if I still can't figure it out.

Share this post


Link to post
Share on other sites

If you are running Windows 10, Windows 8.1 or Windows 8, first run the inbox Deployment Image Servicing and Management (DISM) tool prior to running the System File Checker.
https://support.microsoft.com/en-ca/help/929833/use-the-system-file-checker-tool-to-repair-missing-or-corrupted-system

DISM.exe /Online /Cleanup-image /Restorehealth

 

How do you know if DISM was successful or not and to then run SFC?
On slower systems, it may take 30 minutes or more to complete those tasks 

Why do you keep ignoring advice not to run multiple times? It's your computer so you can do as you like but remind me to keep you away from my computers.

 

Share this post


Link to post
Share on other sites

Before your response, I felt accomplished. Now, I feel like a talentless hack. Maybe I should just wait for the professionals...

I wasn't completely ignoring your advice; I'm fully aware that what I am doing is at my own risk.

My only intention in running it multiple times was to provide that self-healing-ness I was looking for, due to inevitable corruptions that can occur between restarts if the computer goes for a long period of time without restarting. However, "1 hour" is the longest I could specify in the GUI, and I didn't realize that you were specifically trying to get me to use the command-line; I can see now why the command-line is the better option, though.

Using the Task Scheduler GUI, due to the limited amount of control and information that it gave me; I was hoping that by specifying the order of DISM first and SFC second, that it would respect that order and not run SFC until DISM stopped running. But rather than going entirely off of assumption, my intention is to test my hypothesis and see what happens when I run the task in its current state. Since I didn't see SFC in the process list in task manager upon running the task, this has led me to the belief that maybe it will actually perform the actions in serious rather than in parallel.

I still intend to figure out how to make it actually wait until DISM actually reports a successful operation before running SFC, so what I just uploaded could be considered a prototype of sorts. That specifically is what I'd like to figure out.

So, I still learned some important lessons here:

  1. The Task Scheduler GUI is far too limited to do any real work.
  2. Command-line tools are better for anything involving automation, remote administration or headless operation.
  3. Though I have "good" ideas (like a DIY setup for self-healing OS components), I don't listen to instruction, and if I am not explicitly told that I have to do something the hard way, then I instead just do it with whatever tools immediately come to mind.

Share this post


Link to post
Share on other sites

Not trying to be hard on you. Just trying to get you to slow down and take some time to learn more is all. In the long run, knowing more about how to manage and control a computer will benefit you.

The quick and easy get's it working but then tomorrow when you want to do something else you won't be able to without asking. Wouldn't it be better to learn so that you can help yourself and others better in the future.

 

DISM - I don't know if it has error codes you can check or not. So, regardless if it ran or not, without error codes or output to check you don't know what it did and if it needs your help. To automate silently you need to know what it did so you will know if there is something more you need to do.

The same with SFC, you can't just run it blindly and ignore errors or issues requiring user intervention.

 

 

 

Share this post


Link to post
Share on other sites
12 hours ago, Amaroq_Starwind said:

So, I still learned some important lessons here:
The Task Scheduler GUI is far too limited to do any real work.

That's just plain wrong.

Share this post


Link to post
Share on other sites

@Amaroq_Starwind

Trust me, you don't want to be putting any DISM related scripts on a task schedule... google some of my posts blasting microsoft about dism... and what they broke for KB4498523 and more for 18362.1

problems with DISM is one issue... task scheduler is an entire different issue in itself.

i haven't read the rest of the replies, and have only read the original post, and hit reply because DISM on schedule is bad

 

if you get a bad servicing stack this is what will happen to your recovery image:

the right hand side is what how directory structure should be populated

the left hand side is what the SSU did to 18362.30+

(google: "dear microsoft 1903")

SSU-Fkup.thumb.jpg.69498a5a1d6ab039b405bd731ae9906a.jpg

Edited by NeoBeum

Share this post


Link to post
Share on other sites
On 3/20/2019 at 6:40 PM, Amaroq_Starwind said:

All done! For any WipEout fans on the forum, the task scheduler file I made ended up being exactly 2097 characters long.

  Reveal hidden contents


175916193_VerifySystemIntegrity.thumb.png.443e3074ab12954f427b60d7713d6f91.png

I was tempted to give it an 8.3 filename like I usually do, but I decided against it this time.

Verify System Integrity.zipUnavailable

Hi there..  would be curious to know what steps you took to create this task, was looking to do something myself while it does seem to 'complete', any attempt to run DISM/SFC it in a task ends up in access denied errors (which I capture by piping the command output to a log file).  I have tried running as a regular account that was part of the administrator group, then tried the local/default admin account, even tried using the NT AUTHORITY\SYSTEM account, both with or without 'Run With Highest Privileges' options set, doesn't seem to matter.   When I launch the batch file myself manually from an administrative command prompt it doesn't generate any errors, so I'm baffled.   

Anyway I can't download your zip the file seems to be missing/unavailable.

Share this post


Link to post
Share on other sites

Why would you want to run SFC or DISM on a Scheduled Task @Rod_W

Both of those commands would normally rarely be run. If you run SFC  /scannow and it completes successfully then the chances of needing to run that command again within months would be rare unless you're having some type of hardware issue or something where files are not being saved or written correctly. The same with DISM. Once the Store is tested, updated successfully then one should not need to use it again for quite a long time.

What specific issues are you having that makes you think you need to run this?

 

Share this post


Link to post
Share on other sites

I realize there may be risks with these tools in some cases, but just call it a precautionary auto-repair step I'd like to run (even if not technically required very often).  I'm just combining it with a separate backup schedule; I just want to try to maintain the files as they were from the original build of Win10 that was installed, and if something is corrupted to revert any such deviation.   If there are issues as mentioned by NeoBeum, I'll just revert to a previous full system backup anyway.

Share this post


Link to post
Share on other sites

Okay - still seems odd to me but it's your computer to do what you wish. I've not tested such an operation in a scheduled task myself but I'm not aware of any reason it wouldn't work but you may have to use a more advanced setting pointing to a local offline resource as a scheduled task running as system may not have access to the Internet to use for the source.

One way or another I'm sure it is something that can be solved and done. I just don't have time right now to play with it myself.

 

Share this post


Link to post
Share on other sites
On 4/3/2020 at 8:57 PM, Rod_W said:

Anyway I can't download your zip the file seems to be missing/unavailable.

Only forum staff is allowed to download attached files, IIRC.

On 4/3/2020 at 8:57 PM, Rod_W said:

When I launch the batch file myself manually from an administrative command prompt it doesn't generate any errors, so I'm baffled.

I think the fact you're using a batch file might be part of the issue. IIRC, I was entering the commands directly into Task Scheduler. Let me double-check.
---
Also, welcome to the forum.
🦊

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

This site uses cookies - We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.