Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a way [using a batch file] that I can set a system to shutdown PRE-login
but POST-startup? I've tried a scheduled task to run this batch file with the
"/SC ONSTART" flag .. That didn't work. I've tried various registry entries and
couldn't find one that works.

Basically I've created a batch file to perform maintenance with zero user interaction.
One of the actions it performs is setting a "CHKDSK /R" to run on restart, it outputs
a SEPARATE batch file which will delete itself & shut the system down.

I want this separate batch file to run after chkdsk but before the user logs in
that way it still requires zero user interaction... The primary OS this will be
used on is Windows XP Professional.

Thanks much!

share|improve this question
    
Is this something you want to happen every time the machine starts? Or just sometimes? How are you going to determine which times it does and doesn't? –  Izzy Aug 7 '09 at 14:57
    
It will only be initially started by the user...then it runs through maintenance...schedules the chkdsk at the end, outputs the separate batch file....SOMEHOW [trying to figure this part out] schedules the separate batch file to run....then restarts...upon restart it runs the chkdsk....now i just need to get it to shutdown afterwards [prior to the user having to login]. –  Tzadok Aug 7 '09 at 15:05
    
You want to run a script that will delete a logfile, "chkdsk /r" and shutdown the system before a user can log on? –  Benoit Aug 7 '09 at 15:05
    
so, from the first batch file, it outputs ANOTHER batch file to c:\after-restart.bat ... the 3 commands the SECOND batch file runs are as follows ... shutdown -t 90 -f -s............. SCHTASKS /DELETE /TN FinalCleanup /F.......... del /F /Q c:\after-restart.bat............ [[[note]]] it's scheduled to delete that scheduled task because that's how i was trying to start it....i can change that part if I can find a way to start it properly. –  Tzadok Aug 7 '09 at 15:39
add comment

2 Answers 2

up vote 1 down vote accepted

Startup scripts are what you want.

Do something like this:

  • Create a directory, say, "%SystemRoot%\StartupScriptFlags"
  • Grant "Users" "Modify" permission that that directory
  • Make a script to drop a file called "DiskMaintenance" in that folder. Give users rights to run that script.
  • Assign the startup script below to the machine.
    @echo off
    if exist "%SystemRoot%\StartupScriptFlags\DiskMaintenance" call :_disk_maintenance
    goto end

    rem Run CHKDSK and delete flag
    :_disk_maintenance
    rem Run chkdsk, etc
    del "%SystemRoot%\StartupScriptFlags\DiskMaintenance"

    :end

You could supply additional "flag files" in that directory to do Other StuffTM down the road, I suppose.

share|improve this answer
add comment

Use Group Policy to assign a startup script. Startup scripts run at boot. Login scripts run at login. That should help you.

share|improve this answer
    
I actually thought about that as a solution...but how can i edit/change that via CMD prompt? –  Tzadok Aug 7 '09 at 16:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.