If so, software for Windows?

Ai
18

Is there software for Windows where you could somehow add the following command, for example? Command: "if power: false then run shutdown" kp, but somehow stop so that my laptop gets the command to shut down when the power supply is disconnected.

El

No, how is that supposed to work?

If the PC has no more power, it can no longer work and thus of course nothing more.

Ky

There's a laptop. It probably has a battery

El

Oh yes, then something like that would work.

Ai

I said that I use a laptop and then of course it has a battery. Who can read has a clear advantage

Ha

Pretty much any programming language with sufficient authorization

Ha

Laptops usually have a battery.

na

Yes that works in all programming languages. E.g. In Python

if not power:
os.system ("shutdown / s / t 1")

Of course, you have to define the power value beforehand and make it available to the program.

Re

I guess he means the battery is running

je

OP presumably means: If the power cord is disconnected, the laptop should be shut down.

El

Yes, I've been told by two others. But thanks

Ai

And how can I keep it running so that it always checks whether there's power / it is currently connected to the power supply?

He

You have to deal with Powershell a bit. On Stackoverflow someone asked the same question:

https://stackoverflow.com/...isconnects

Ha

AutoIT could possibly also help.

na

With a while loop around it

while true:
if not power:
os.system ("shutdown / s / t 1")

But as I said, you first have to define what the Power parameter is and how this program should read this parameter.

In any case, this program would never stop and as soon as the parameter power is false it switches off the PC.

Ai

Oh god, i'm really not the expert in that sort of thing. Absolutely no idea how something like that works, haha

na

Well, check out some tutorials for Python or any other programming language. They are just there to automate things like that.

ay

You should add a short pause in the loop. Otherwise, this short program could create quite a bit of processor load.

na

It certainly does, depending on how you query the true parameter, but the whole thing is just an example, the power parameter must also be defined and set.