Jump to content
Sign in to follow this  

Laptop power state

Recommended Posts


Hi, I've already trawled the forum looking for an answer to this but without much luck :

Quite simply I want to check to see if the laptop, the script is running on, is attached to the AC adapter or running on battery.

Then I want the script to carry on if it is, and throw up a message box prompting the user to attach the power supply if it isn't.

I found some information on creating an array from WMI and then tried converting it to a string and it all gets a bit messy. Is there a simple way of finding out if it's on AC or DC. I don't need to know charging time remaining etc, Just on battery or on AC. Is it really that difficult?

Thanks in advance, my head is about to go bang.

Share this post

Link to post
Share on other sites

Here's a UDF that should make life easier for you:

Thanks abberation, I had already found this but I'm struggling to get the information this provides in a format that I can use. How can I query the array to get a simple true or false or 1 or 0.

Do I use _ArraySearch _ArrayToClip _ArrayToString?

I'm at the limit of my AutoIt knowledge now.

Share this post

Link to post
Share on other sites

After the _ArrayDisplay code, add these lines:

If $batt[0] = 0 Then
    MsgBox(0, "", "The laptop is not plugged in")
ElseIf $batt[0] = 1 Then
    MsgBox(0, "", "The laptop IS plugged in")
    MsgBox(0, "", "I don't know if the laptop is plugged in")

The variable $batt[0] holds the answer. If it is equal to 0 then the laptop is not plugged in. If equal to 1 then it is.

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.