2

At our company, the people stop working at 7PM. At 8PM we run a scheduled task with GPO to warn the logged-in user that the computer is going to shutdown. This works fine.

When no one is logged-in and the computer is still running, we would like to shutdown the computer. Does anybody have any idea how to do this?

We run Windows Server 2012 and our clients are Windows 7.

glendc
  • 31
  • 1
  • 1
  • 4
  • 2
    If you are going to do this don't forget to take into account your strategy for updates/antivirus scans, etc. Users waiting hours for their PCs to get up to speed the morning after can counteract energy savings plus they complain a lot. :) – JamesRyan Apr 28 '14 at 13:27
  • You might also consider leveraging the power policies and sleep states that Windows has to use sleep and hibernation, rather than a hard shutdown. – Ryan Ries Apr 28 '14 at 13:34
  • How many workstations are in your environment? The reason I ask, is because there is a software vendor out there (you may have heard of them, they are called Faronics), that I use for a lot of other services and they happen to have software that does this. You may be saying, "why would I want to pay to have this happen?" and the answer is because you can then save a lot of money. They pitch an average of $50 saved per computer per year. If you have a couple hundred computers, that's easily $10,000 or more you can save and you don't have all the management hassle trying to do it yourself. – Brad Bouchard Apr 28 '14 at 15:47
  • 1
    @BradBouchard there probably is a software for everything, but a shutdown is so trivially scripted that I would hesitate recommending a packaged software solution to anybody. – the-wabbit May 07 '14 at 06:42

5 Answers5

1

The computer shutdown is rather easy - as others have noted you might use the shutdown command for this. If you have configured your machines' local firewalls to allow SMB and RPC from management hosts (e.g. by enabling remote administration exceptions in group policies), you could trigger the shutdowns centrally for all machines in your domain using the /m \\computername parameter to your shutdown call:

shutdown /s /f /t 30 /m \\pcXXX /c "Automatic shutdown"

A more flexible version of the shutdown command is offered by SysInternals as psshutdown. Among other things, it allows for user interaction (i.e. a user would be given the opportunity to abort a shutdown request if desired)

Now for determining if a user is logged on to a machine, you would have to test each of them, e.g. using the quser command. The typical output would look like:

C:\Users\denis>quser
 USERNAME              SESSIONNAME        ID  STATE   IDLE TIME  LOGON TIME
>denis                 console             1  Active      none   22.04.2014 15:11

You could filter for a string like "Active" to determine if you can shut down safely. A batched version might look like this:

shutdownunused.bat

ping %1
if errorlevel 1 ( echo %1 seems offline && exit 1)
quser /SERVER:%1 | find "Active"
if %errorlevel% == 1 shutdown /s /f /t 30 /M \\%1 /c "Automatic shutdown"

calling shutdownunused.bat pc1234 would test and shut down pc1234 if it is a) pingable and b) has no user logged on actively (it would shut down a host if the user is logged on, but disconnected or has his machine locked). This can be scripted to your liking - either by using a local-only version as a scheduled task or centrally triggered from a management host through enumeration of all stations in your domain. The advantage of the latter approach is that it would be easier to keep logs and create statistics.

the-wabbit
  • 40,737
  • 13
  • 111
  • 174
0

Outside of what was mentioned about Windows Updates, AV scans and boot up time. You could leverage the same Scheduled Task GPO you're mentioning to run a batch file on the computer with shutdown /f /t 0.

Group policy location: Computer Configuration, expand the Preferences folder, and then expand the Control Panel Settings, Right-click the Scheduled Tasks node, point to New

.

Nixphoe
  • 4,584
  • 7
  • 34
  • 52
0

Nixphoe has got the command you're looking for. A few suggestions though: First, when creating the scheduled task, make sure you set under the "Conditions" Tab (In Create New Task) that it will not get triggered until the computer has been idle for xxx minutes - This will help prevent calls from users staying late having their computers "turn off by themselves" while they are working.

Also, the use of a batch file - although fine - is unnecessary for a "one liner" like that, you can simply go to the "Action" Tab in create new task, under "Program/Script" simply type "Shutdown" and under arguments "/s /f /t 30"(or whatever number) it will run the entire line

Shutdown /s /f /t 30

I suggest /t 30 instead of /t 0 since it will give the end user a little warning before you force the shutdown. Let us know how it goes!

0

I use the following command in a batch file, which is then issued to each selected machine as a Scheduled Task by my deployment solution:

for /f %%i IN ('quser ^| find /c /i "active"') DO (if %%i EQU 0 shutdown /s)
0

You could also use the Stop-Computer CMDLet. by default, if a user is still logged on it won't shutdown the computer, in that case you would need to use -Force