Government Security
Network Security Resources

Jump to content

Photo

Help writing batch file - prompt user for shutdown windows xp

- - - - - windows server network advanced
  • Please log in to reply
No replies to this topic

#1 wiloskyline

wiloskyline

    Private First Class

  • Members
  • 25 posts

Posted 01 April 2009 - 08:34 PM

Batch File: Prompt user about shutdown

O.S Platform: Windows XP Sp3

Purpose:
To create a batch file for a network of Windows XP computers. Each computer on the network will have a scheduled task that runs at the end of the day. This schedue task will run a batch file called 'promptshutdown.bat'. This batch file is designed to shutdown the computer if its not in use, and if someone is using it, prompt them how long to wait before shuting down.
It will do the following processes

Aim:
Prompt user if they want to shutdown their computer
If there is no user input for X seconds then shutdown
If the user says “yes”, shutdown after 30 seconds – display countdown timer
If the user says “no”, prompt with new menu
New menu: (select option)
Shutdown in:
Option 1: 15 Minutes
Option 2: 30 Minutes
Option 3: 60 Minutes
Option 4: Dont shutdown at all
Close the batch file

Puesdo Code:
Do you want to shutdown your computer? [y/n]
If yes [(shutdown -s -t 30]
Else
Prompt the user with 4 options
Options are:
Option 1: 15 Minutes
Option 2: 30 Minutes
Option 3: 60 Minutes
Option 4: Dont shutdown at all
End batch file

Example Code:
@echo off
CLS
set /p ans=Do you want to shutdown this computer? [y/n]^>
if "%ans%"== "y" (
goto : SHUTDOWN -S -T 500
) else (
goto :Start
ECHO When do you want to shutdown?
ECHO Press number of choice followed by the Enter key
ECHO 1: Fifteen Minutes
ECHO 2: Thirty Minutes
ECHO 3: Sixty Minutes
ECHO 4: Quit
SET Choice=
SET /P Choice=""
IF '%Choice%'=='1' GOTO Fifteen
IF '%Choice%'=='2' GOTO Thirty
IF '%Choice%'=='3' GOTO Sixty
IF '%Choice%'=='4' GOTO End
CLS
ECHO "%Choice%" is not valid
ECHO Try again
GOTO Start
:Fifteen
SHUTDOWN -S -T 900
GOTO End
:Thirty
SHUTDOWN -S -T 1800
GOTO End
:Sixty
SHUTDOWN -S -T 3600
GOTO End
:End
CLS

This code does not work however

Concerns:
Is this the best way of doing what I want to do?
With the shutdown -s -t method, will this cause undesired problems with crashing out of programs/processes?
I want to use a batch file, I dont want to use a server domain enviroment and I dont want to use GPO's.

Thanks in advanced
K1LL9





Also tagged with one or more of these keywords: windows, server, network, advanced