Auto Shutdown maintenance using an .Inf

Posted in Windows XP by Community Submission

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:

2. 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:

3. 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:

4. 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)

5. 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 :)

Advertisement
Free Computer Magazines and eBooks