?
Solved

Warn the User that the PC will shutdown

Posted on 2009-04-15
11
Medium Priority
?
519 Views
Last Modified: 2012-05-06
Hello,
I have managed to solve my problem partially, thanks to bluntTony, as he provided me with a script that allows me to schedule a Shutdown task at a particular time to be executed and shut down the client PCs.
the the problem that Im facing now is that if I schedule it like that it will shut down the PC directly without any warning for the user, and if by chance an employee is still working late at the office and it comes to the time that it is scheduled for the PC to be turned off, it will shut down and all his work will be lost.

I have attached the VB code provided by bluntTony and what Im looking for now is a way to warn the user 15 min before the shutdown action, and allow him to Cancel it when needed.

Set objShell = CreateObject("Wscript.Shell")
set objWMI = GetObject("winmgmts:\\.\root\cimv2")
set colScheduledJobs = objWMI.ExecQuery("Select * from Win32_ScheduledJob")
For each objJob in colScheduledJobs
	If InStr(UCase(objJob.command),"SHUTDOWN") > 0 Then	booFound = True
Next
If Not booFound Then objShell.Run("%systemroot%\system32\at 19:00 shutdown.exe -s -f -t 30")

Open in new window

0
Comment
Question by:stalliondz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 4

Expert Comment

by:anuroopkoka2005
ID: 24146195
Hi i have script that use can use with the help of Windows Scheduled Task and PSSHutdown...

using PSShutdown.exe u can even reboot, shutdown, log off, u can do it forcefully...
This PSshutdown will prompt for saving the file the user is currently working on... By default this script will reboot only..if u want to shutdown just change the arguement u pass on to...

It will take the machine name as input from the txt file...
This script genetates report...download the psshutdown.exe from the internet...



:: BATCH SCRIPT START 
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET InputFile=C:\Reboot_Script\Machines.txt
SET OutputFile=C:\Reboot_Script\RestartStatus.csv
 
IF NOT EXIST "%InputFile%" ECHO "%InputFile%" file does not exist. &GOTO :EndScript
FOR %%R IN ("%InputFile%") DO IF %%~zR EQU 0 ECHO "%InputFile%" file is empty. &GOTO :EndScript
IF EXIST "%OutputFile%" DEL /F /Q "%OutputFile%"
 
FOR /F %%c IN ('TYPE "%InputFile%"') DO (
        ECHO Processing: %%c
        PING -n 1 -w 1000 %%c|Find /I "TTL" >NUL
        IF NOT ERRORLEVEL 1 (
			ECHO Restarting %%c >>"%OutputFile%"
			PSShutdown \\%%c -r >>C:\Reboot_Script\Result.csv
        )ELSE (ECHO Unable to connect %%c: system may be offline.>>"%OutputFile%"))
 
ECHO. &ECHO Script complete. Check "%OutputFile%" file.
:EndScript
ENDLOCAL
EXIT /B 0
:: BATCH SCRIPT END

Open in new window

0
 
LVL 49

Assisted Solution

by:Akhater
Akhater earned 200 total points
ID: 24146205
in  shutdown.exe -s -f -t 30
the 30 is 30 seconds

if you change this value to 900 seconds (i.e. 15 min)

it will give a warning to the user before 15 min

0
 

Author Comment

by:stalliondz
ID: 24146524
anuroopkoka2005 thanks for the quick responce but that's not what i was looking for. as using that way i will have to create a file for all the Client PCs inthe company, and they just keep changing. can't keep on updating that on a daily basis.

where as the way i am using, i will just have to run it through the GPO as a startup script and that's it.
thanks Akhater as i didn't know that that value is the Seconds. and i will change it. But is there anyways that could give the user the ability to Cancel the shutdown if he's still working ???? that's what i need.
0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 4

Assisted Solution

by:anuroopkoka2005
anuroopkoka2005 earned 200 total points
ID: 24146553
just ask the user to type shutdown -a in the run windows and that will do the trick...
0
 
LVL 4

Expert Comment

by:anuroopkoka2005
ID: 24146567
Description of the Shutdown.exe Tool

Shutdown.exe uses the following syntax:
shutdown \\computername /l /a /r /t:xx "msg" /y /c

You can use the following switches with Shutdown.exe:

\\computername: Use this switch to specify the remote computer to shut down. If you omit this parameter, the local computer name is used.

/l (Note that this is a lowercase "L" character): Use this switch to shut down the local computer

/a: Use this switch to quit a shutdown operation. You can do this only during the time-out period. If you use this switch, all other parameters are ignored.

/r: Use this switch to restart the computer instead of fully shutting it down.

/t:xx: Use this switch to specify the time (in seconds) after which the computer is shut down. The default is 20 seconds.

"msg": Use this switch to specify a message during the shutdown process. The maximum number of characters that the message can contain is 127.

/y: Use this switch to force a "yes" answer to all queries from the computer.

/c: Use this switch quit all running programs. If you use this switch, Windows forces all programs that are running to quit. The option to save any data that may have changed is ignored. This can result in data loss
0
 
LVL 4

Assisted Solution

by:anuroopkoka2005
anuroopkoka2005 earned 200 total points
ID: 24146580
you can even refer to the below link fior the same:--

http://support.microsoft.com/kb/317371
0
 
LVL 27

Assisted Solution

by:bluntTony
bluntTony earned 600 total points
ID: 24147101
Looks like this has basically been covered, but you can use the -c switch to add a comment instructing the user what to do, and extend the wait period to 15 mins, as in the below edited script:
Set objShell = CreateObject("Wscript.Shell")
set objWMI = GetObject("winmgmts:\\.\root\cimv2")
set colScheduledJobs = objWMI.ExecQuery("Select * from Win32_ScheduledJob")
For each objJob in colScheduledJobs
	If InStr(UCase(objJob.command),"SHUTDOWN") > 0 Then	booFound = True
Next
If Not booFound Then objShell.Run("%systemroot%\system32\at 19:00 shutdown.exe -s -f -t 900 -c ""Your machine is scheduled to shut down in 15 mins. To cancel, type shutdown -a from the command prompt to abort""")
 

Open in new window

0
 
LVL 49

Assisted Solution

by:Akhater
Akhater earned 200 total points
ID: 24152500
just one more additional note,

The shutdown -a will not work unless the user have elevated privileges on the machine

0
 
LVL 27

Accepted Solution

by:
bluntTony earned 600 total points
ID: 24155741
The privileges required are both of the following:

Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\Force shutdown from a remote system
Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\Shut down the system
 
The users will need these to run shutdown.exe (including the abort). Assign this to your users and they will be able to cancel it...
0
 

Author Comment

by:stalliondz
ID: 24156211
thanks alot guys, that was exactly what i needed.

Best Regards
0
 

Author Closing Comment

by:stalliondz
ID: 31570330
Thanks for the efforts, Really helpfull
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses
Course of the Month15 days, 17 hours left to enroll

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question