question

geercom-4104 avatar image
0 Votes"
geercom-4104 asked RLWA32-6355 commented

Create ps1 or batch file to execute DSIM and SFC with admin privileges using Task Scheduler

Thank you for your kind assistance.

I can run DSIM and SFC commands manually. I can create tasks in Task Scheduler. I cannot create a .ps1 or .bat file to run DSIM and SFC commands. Can you guide me?

windows-10-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
0 Votes"
MotoX80 answered

Please review my reply in this post.

https://docs.microsoft.com/en-us/answers/questions/833713/application-is-working-fine-when-runned-manually-b.html

Just use notepad and create a .bat file in some directory that runs whatever program you want to run. Echoing the date time in the bat file can be useful for troubleshooting. In the scheduled task, set it to launch cmd.exe. In the arguments field, point it to the .bat file and whatever log file and folder names you wish to use.

Set the task to run as the SYSTEM account and check the "Run with highest privileges" box. Run the task and then review the log file to see what it did.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered geercom-4104 commented

Hello

Thank you for your question and reaching out.
I can understand you are having some issues \ queries related to running DISM and SFC command using .bat file

You can use below .bat file code block to achieve this.


@ECHO OFF
DISM /Online /Cleanup-Image /RestoreHealth

Sfc /scannow




Then save as C:\Temp\MyComp.bat to your desktop


Then you can configure in your Task Scheduler with path of this .bat file and make sure you also set proper privilege User account to run this .bat file within Task scheduler.



--If the reply is helpful, please Upvote and Accept as answer--

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you.

Why does the bat file have a name that includes the full path to somewhere, which, coincidentally is not where the file is? You use the path to where it is located on the desktop, not the path in this name you gave it, right?

0 Votes 0 ·
MotoX80 avatar image
0 Votes"
MotoX80 answered RLWA32-6355 commented

which, coincidentally is not where the file is? You use the path to where it is located on the desktop, not the path in this name you gave it, right?

We have no way of knowing where you saved any file on your PC. So anything that a forum user would post is essentially an example of how to call a .bat file. The actual folder that you put a file in is up to you.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Since the scheduled task that executes the batch file is to run as SYSTEM I suggest that the batch file is placed in a secure location in the file system that requires administrator privileges for write access.

0 Votes 0 ·