|
|
|||||||
Our KIX Script can identify if a computer is a laptop or not, but I need to know if the laptop is connected to power or if it is running from its battery. Most searches just return if how to identify a laptop vs a desktop. |
||||||||
|
|
|||||||
Hmmm... I might know a back door method if we can't find it via wmi... did you try kixomatic? |
||||||||
|
|
|||||||
This might be of use via WMI...Unfortunately I have no way of testing here in the office. http://msdn.microsoft.com/en-us/library/windows/desktop/aa394074%28v=vs.85%29.aspx |
||||||||
|
|
|||||||
Using WMI: Code: $strComputer = @WKSTA $objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\wmi") $colItems = $objWMIService.ExecQuery("Select * From BatteryStatus Where Voltage > 0") For Each $objItem in $colItems ? "Battery: " + $objItem.InstanceName ? "On AC Power: " + $objItem.PowerOnline ? "Battery is Discharging: " + $objItem.Discharging ? "Battery is Charging: " + $objItem.Charging ? "Remaining capacity: " + $objItem.RemainingCapacity Next Sleep 5 |
||||||||
|
|
|||||||
How Can I Tell Whether a Laptop Computer is Running Off Batteries? http://blogs.technet.com/b/heyscriptingg...-batteries.aspx (edit: same code as Marts above) ... |
||||||||
|
|
|||||||
Nice Mart! Just to elaborate a bit more... Code: [postprep]If UsingBattery() ? "on battery power" Else ? "plugged in" Endif get $ Function UsingBattery() $objWMIService = GetObject("winmgmts:\\" + @WKSTA + "\root\wmi") $colItems = $objWMIService.ExecQuery("Select * From BatteryStatus Where Voltage > 0") For Each $objItem in $colItems $UsingBattery = IIF($objItem.PowerOnline,0,1) Next EndFunction |
||||||||
|
|
|||||||
Originally Posted By: Allen ... ... My code also works on Win7. I did not pull the power cord from my laptop because it is in a dock with all kinds of stuff connected but it should work just fine. Nice UDF Shane. Going to post it in the UDF section? Maybe an optional parameter for the other stuff like remaining capacity and so on could be useful. |
||||||||
|
|
|||||||
I don't know why the code didnt work... the vbs didnt work either. The UDF works for me though. The UsingBattery should go in the UDF as is, with another UDF for all the other stuff. Man KixKicks... you got it good right now with everyone chipping in. |
||||||||
|
|
|||||||
Quote: Man KixKicks... you got it good right now with everyone chipping in It would make a good UDF Mart...but I pretty much just modified your code and I don't want to steal the credit, so if you want to make one, go for it. If you're too busy then I'll do it. |
||||||||
|
|
|||||||
AWESOME, everyone!!! Thanks for your help... Maybe there should be an achievement for most questions in a week (newbie award)...LOL |
||||||||
|
|
|||||||
Originally Posted By: ShaneEP ... It would make a good UDF Mart...but I pretty much just modified your code and I don't want to steal the credit, so if you want to make one, go for it. If you're too busy then I'll do it. One of our servers went to visit its maker without any chance of reincarnation so I have an SQL installation and database recovery planned for this morning. I'll see if I can find some time later today. |
||||||||
|
|
|||||||
oh... historic work. would be kinda nice to do that myself for nostalgy's sake :P |
||||||||
|
|
|||||||
See: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=204951#Post204951 |