Skip to main content

Auto Shutdown maintenance using an .Inf

Posted November 2002 by Steve Sinchak

Follow the steps outlined below to schedule automatic regular maintenance of your PC and then have it shutdown automatically.

Scope:

Windows XP Pro
Installed on C:
NTFS partition

Login as Admin...

  1. Open notepad and paste in these lines

cd\
c:
cd windows\system32
defrag c: /f
chkntfs c:

Save the file as maint.bat in the root of C:

  1. Open notepad and paste in these lines

[version]
Signature= "$CHICAGO$"
AdvancedINF= 2.5,"advpack.dll"

; This is the install part.

[DefaultInstall]
RunPreSetupCommands=Tst.PreSetup
RunPostSetupCommands=Tst.PostSetup

[Tst.PreSetup]
c:\maint.bat

[Tst.PostSetup]
c:\WINDOWS\SYSTEM32\TSSHUTDN.EXE 0 /DELAY:0 /POWERDOWN

Save the file as maint.inf in the root of C:

  1. Open notepad and paste in this line

c:\WINDOWS\System32\rundll32.exe advpack.dll,LaunchINFSectionEx c:\maint.inf,DefaultInstall,,32

Save the file as shutdown.bat in the root of C:

  1. Go to Start/All Programs/Accessories/System Tools/Scheduled Tasks

Add a Scheduled Task
Browse to the C: drive and select shutdown.bat
Select Weekly (change the interval to every 2 weeks)
Set the time for late at night (something like 2am)

  1. You can set a 2nd scheduled reminder the night of the maintenance (use a text file with your reminder words) to remind you to leave your pc turned on. (Just turn off the monitor).

That's it.

What's going on?

When the scheduled task starts it will execute shutdown.bat. Shutdown.bat will then execute maint.inf. When maint.inf starts it will execute this section first:

[Tst.PreSetup]
c:\maint.bat

Maint.bat will then execute and defrag the drive. Maint.bat will then execute chkntfs c: (This will direct XP to run a chkdsk on the NTFS Partition (c:) on the next reboot and fix any errors automatically. Next, the maint.inf will execute this section:

[Tst.PostSetup]
c:\WINDOWS\SYSTEM32\TSSHUTDN.EXE 0 /DELAY:0 /POWERDOWN

which will then shutdown XP and power off the box.

*Note

When this line chkntfs c: is executed in maint.bat XP will determine if it needs to run on next boot. If it doesn't you will receive a message that (C: is not dirty). If it needs to run then a message will appear in the dos window informing you that it will run on next boot. To visualize what I'm talking about temporarily change the maint.bat to look like this

cd\
c:
cd windows\system32
rem defrag c: /f
chkntfs c:
pause

Execute maint.bat

At any rate, this is just an FYI to clear up any concerns if you don't see chkntfs execute on the next boot.

Lastly, when this line executes

[Tst.PostSetup]
c:\WINDOWS\SYSTEM32\TSSHUTDN.EXE 0 /DELAY:0 /POWERDOWN

it takes approximately 10-15 seconds before the pc shuts down. So please be patient when you're testing this out. The delay won't matter as you'll be off in slumberland or whatever else we do at 2am :)

Related Posts


If you own a Google Chromecast streaming device, you can easily share a browser tab in Chrome browser or even your entire desktop.  This can be very useful when presenting from your laptop or if you just want to watch something on a big screen that is only on your PC.  The only requirement is you must be on the same network as your Chromecast...

Read More

If you are a fan of minimalist desktop experiences, hiding the desktop icons are an easy way to clean up the Windows interface.  Instead of saving everything to your desktop, use the default profile folders such as downloads and documents.  Actually hiding all the icons on your desktop is a very simple customization hidden in the right-click context menu.  Just right-click on the desktop, select View...

Read More

Google security researchers have published details about a major security flaw found in the SSL protocol that is used to encrypt data transferred between your browser and a web server. SSL is typically used in situations where logon credentials are validated...

Read More

Enabling two-factor authentication is a great way to add an additional level of protection to your Microsoft account.  Even if your password is stolen, your account is still protected because two-factor authetication requires an additional level of verification to log in. Microsoft calls their version of two-factor authentication "two-step verification" and it works by providing you with a random code...

Read More