Is there a way to detect weather my laptop is using the battery or
power-cable programatically in Windows Script? I have an IBM ThinkPad
A30 with Windows 2000 SP3 with a background service that takes up a
large processing power when activated. If possible, I'd like to
shut-down this service automatically whenever I un-plug the laptop,
then start it back up again when I plug it back in.

I have search the forum for solution and try to use WMI win32_battery
to get information on my Windows XP Pro, but it seems not work, for
the properitiers of "BatteryStatus", it just return "1 - Other" when
my notebook is using battery and return "2 - unknow" when I attach
power cable to my notebook, but it should return "charging" or "using
battery".

Why I want to get information of power status ? I want to
automatically install windows xp sp2 patch for all my office desktop
and notebook sliently , but it seems not work on notebook when it's
using battery power.

Is somebody can help me ? Thanks in advance.

Motor.

Re: Detecting Battery Mode programatically by Scott

Scott
Thu Dec 30 14:51:51 CST 2004

Actually, IIRC, Service Pack 2 already has code to prevent installing if the
system is running on battery power... Try it.
--
Scott Fenstermacher
Network Engineer
Levi, Ray and Shoup, INC


"Motor Wu" <motorwu@kimo.com> wrote in message
news:mea8t0hi663pjug99dal53t7761vjgqr6k@4ax.com...
> Is there a way to detect weather my laptop is using the battery or
> power-cable programatically in Windows Script? I have an IBM ThinkPad
> A30 with Windows 2000 SP3 with a background service that takes up a
> large processing power when activated. If possible, I'd like to
> shut-down this service automatically whenever I un-plug the laptop,
> then start it back up again when I plug it back in.
>
> I have search the forum for solution and try to use WMI win32_battery
> to get information on my Windows XP Pro, but it seems not work, for
> the properitiers of "BatteryStatus", it just return "1 - Other" when
> my notebook is using battery and return "2 - unknow" when I attach
> power cable to my notebook, but it should return "charging" or "using
> battery".
>
> Why I want to get information of power status ? I want to
> automatically install windows xp sp2 patch for all my office desktop
> and notebook sliently , but it seems not work on notebook when it's
> using battery power.
>
> Is somebody can help me ? Thanks in advance.
>
> Motor.



Re: Detecting Battery Mode programatically by Motor

Motor
Wed Jan 05 21:22:10 CST 2005

Thanks, In fact, I have got some script on Microsoft Script Center,
but it seems return invalid battery information, is there anybody know
what I have miss ?

http://www.microsoft.com/technet/scriptcenter/scripts/hardware/power/hwpwvb01.mspx

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_battery.asp

On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery")

For Each objItem in colItems
Wscript.Echo "Availability: " & objItem.Availability
Wscript.Echo "Battery Status: " & objItem.BatteryStatus
Wscript.Echo "Chemistry: " & objItem.Chemistry
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "Design Voltage: " & objItem.DesignVoltage
Wscript.Echo "Device ID: " & objItem.DeviceID
Wscript.Echo "Estimated Run Time: " & objItem.EstimatedRunTime
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Power Management Capabilities: "
For Each objElement In objItem.PowerManagementCapabilities
WScript.Echo vbTab & objElement
Next
Wscript.Echo "Power Management Supported: " & _
objItem.PowerManagementSupported
Wscript.Echo
Next



On Thu, 30 Dec 2004 14:51:51 -0600, "Scott Fenstermacher"
<sfenstermacher@lrs.com> wrote:

>Actually, IIRC, Service Pack 2 already has code to prevent installing if the
>system is running on battery power... Try it.


Re: Detecting Battery Mode programatically by Motor

Motor
Sat Jan 08 09:37:52 CST 2005

Is anybody know this ?

On Thu, 06 Jan 2005 11:22:10 +0800, Motor Wu <motorwu@gmail.com>
wrote:

>Thanks, In fact, I have got some script on Microsoft Script Center,
>but it seems return invalid battery information, is there anybody know
>what I have miss ?
>
>http://www.microsoft.com/technet/scriptcenter/scripts/hardware/power/hwpwvb01.mspx
>
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_battery.asp
>
>On Error Resume Next
>
>strComputer = "."
>Set objWMIService = GetObject("winmgmts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer &
>"\root\cimv2")
>
>Set colItems = objWMIService.ExecQuery("Select * from Win32_Battery")
>
>For Each objItem in colItems
> Wscript.Echo "Availability: " & objItem.Availability
> Wscript.Echo "Battery Status: " & objItem.BatteryStatus
> Wscript.Echo "Chemistry: " & objItem.Chemistry
> Wscript.Echo "Description: " & objItem.Description
> Wscript.Echo "Design Voltage: " & objItem.DesignVoltage
> Wscript.Echo "Device ID: " & objItem.DeviceID
> Wscript.Echo "Estimated Run Time: " & objItem.EstimatedRunTime
> Wscript.Echo "Name: " & objItem.Name
> Wscript.Echo "Power Management Capabilities: "
> For Each objElement In objItem.PowerManagementCapabilities
> WScript.Echo vbTab & objElement
> Next
> Wscript.Echo "Power Management Supported: " & _
> objItem.PowerManagementSupported
> Wscript.Echo
>Next
>
>
>
>On Thu, 30 Dec 2004 14:51:51 -0600, "Scott Fenstermacher"
><sfenstermacher@lrs.com> wrote:
>
>>Actually, IIRC, Service Pack 2 already has code to prevent installing if the
>>system is running on battery power... Try it.