S
S
sbh2015-09-03 08:30:24
PowerShell
sbh, 2015-09-03 08:30:24

How to turn off the computer when inactive for a certain time?

I never managed to set up sleep on several computers.
They do not fall asleep and at least what you do.
Actually, then the idea arose to simply turn them off when idle, for example, 2 hours.
How to do it better?
Write a script - the first thing that comes to mind, but how to determine the PC idle time?
Are there any other ways or ideas?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
MrDywar Pichugin, 2015-09-03
@sbh

I recently learned (about 8 months ago) that in PowerShell you can use C # directly in a script.

Add-Type @'
    public class Foo
    {
        public string GetComputerName()
        {
            return System.Environment.MachineName + " it works!";
        }
    }
'@

$foo = New-Object Foo

$foo.GetComputerName()

This will allow you to write a method that will return whether the user is working on a PC or not, and based on this, make a decision about the further operation of the PC. You can also do all this in C# and only call it in a script.
The script cannot be run many times with the addition of a type, there will be an error.
To do this, save the creation of the type in another script and import it into the main one via
When you make a change to the type, you must restart the ISE PowerShell session.
C# is richer for detecting user activity.

E
Eugene, 2015-09-03
@yellowmew

To begin with, answer yourself the question: how will you determine the inactivity of the computer?
If your computers do not go to sleep according to the standard scheme, then there is a suspicion that there is no inactivity, in fact, or some program, service or device is preventing the computer from going to sleep.
Solve these problems - and do not have to collective farm.
Although, of course, you can come up with a "cunning" scheme like: press the pop-up button once every 15 minutes, otherwise the computer will explode and go to sleep.
Then the script will help, yes.

H
Hitmanp, 2015-09-03
@Hitmanp

The most logical option. Through the task scheduler. We launch a batch file with a larger timer - 1.bat
Suddenly, the user is still at the workplace.
shutdown -s -t 600 -c "The computer will turn off in 10 minutes"
If the user is still in place, then create a batch file for him on the desktop 2.bat
shutdown -a
It will work if the user has admin rights.
If the user has rights - Users, then the session will only end. Conclusion - in the scheduler we prescribe - run on behalf of the Administrator. Specify - regardless of user registration.

R
Ranwise, 2015-09-07
@Ranwise

if you have windows vista \ 7 \ 8 then check the task scheduler, maybe updates / defragmentation are downloading at night, etc., which prevents falling asleep or, on the contrary, wakes up the PC

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question