Help with .bat file

Discussion in 'Scripting' started by lobo11, Jan 17, 2016.

  1. lobo11

    lobo11 TOMAHAWK CHOP

    Feb 16, 2012
    6,473
    4,587
    210
    Anyone know how to make .bat file to run sfc /scannow every night as a scheduled task, thanks:worthy:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. pisthai

    pisthai Imperfect Human

    Jul 29, 2009
    6,814
    1,997
    210
    Go to Macro Toolworks, download the free version and create a Trigger for a time-based macro! It's quite easy!

    That apps could do much more, include a lot automated processes etc.!!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. dhjohns

    dhjohns MDL Guru

    Sep 5, 2013
    3,285
    1,731
    120
    #3 dhjohns, Jan 17, 2016
    Last edited by a moderator: Apr 20, 2017
    Here is what I did. I created a .cmd file (same as .bat, but I prefer,) and named it sfc.cmd
    Code:
    sfc /scannow
    I placed it on C-drive. Then I created a shortcut, and placed it on C-drive also. I click on properties, advanced, and set it to run as administrator. Then I went into task scheduler and created a task to run every night at 12:01 a.m. Here is the file. Save it as .xml in notepad, open Schedule Tasks, and import. You are good to go.
    Code:
    <?xml version="1.0" encoding="UTF-16"?><Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
      <RegistrationInfo>
           <URI>\SFC</URI>
      </RegistrationInfo>
      <Triggers>
        <CalendarTrigger>
          <StartBoundary>2016-01-17T12:01:00</StartBoundary>
          <Enabled>true</Enabled>
          <ScheduleByDay>
            <DaysInterval>1</DaysInterval>
          </ScheduleByDay>
        </CalendarTrigger>
      </Triggers>
      <Principals>
        <Principal id="Author">
          <GroupId>S-1-5-32-545</GroupId>
          <RunLevel>HighestAvailable</RunLevel>
        </Principal>
      </Principals>
      <Settings>
        <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
        <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
        <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
        <AllowHardTerminate>true</AllowHardTerminate>
        <StartWhenAvailable>false</StartWhenAvailable>
        <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
        <IdleSettings>
          <StopOnIdleEnd>true</StopOnIdleEnd>
          <RestartOnIdle>false</RestartOnIdle>
        </IdleSettings>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <Enabled>true</Enabled>
        <Hidden>false</Hidden>
        <RunOnlyIfIdle>false</RunOnlyIfIdle>
        <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
        <UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
        <WakeToRun>false</WakeToRun>
        <ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
        <Priority>7</Priority>
      </Settings>
      <Actions Context="Author">
        <Exec>
          <Command>C:\sfc.cmd</Command>
        </Exec>
      </Actions>
    </Task>
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. deadock

    deadock MDL Novice

    Jan 11, 2016
    27
    7
    0
    technet.microsoft.com/en-us/library/cc748993.aspx

    windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7
     
  5. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    876
    457
    30
    use taskschd.msc define your action and triggers and you're done. takes about 5min.
    also can import/export it as xml (for other machines)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. rpo

    rpo MDL Addicted

    Jan 3, 2010
    553
    323
    30
    https://technet.microsoft.com/en-us/library/cc722129.aspx :

    The following list contains a description of each action and the action settings.
    • Start a program

    This action starts a program or script. In the Program/script text box, enter the name of the program or script you want to start. If the program or script takes command line arguments, you can supply these arguments in the Add arguments (optional) text box. In the Start in (optional) text box, you can specify the working directory for the command line that executes the program or script. This should be either the path to the program or script file or the path to the files that are used by the executable file.