WMI和笔记本电池 [英] WMI and Laptop Battery

查看:109
本文介绍了WMI和笔记本电池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候:



我是VB脚本的新手。我从这个网站以及其他网站上学到了很多东西。但是我遇到了一个我想写的脚本概念的问题,我需要朝着正确的方向推进。



首先是一个小背景。我有一台带WinXP的旧笔记本电脑。我想把这台笔记本电脑插入电源插座。当电源耗尽时,我希望我的脚本将笔记本电脑从电池上耗尽的时间和日期写入文件。当电源恢复并且笔记本电脑没有交流电时,它将在相同的日志文件中写入恢复交流电源的时间和日期。我基本上想要使用这台笔记本电脑在我离开时记录家里的停电。



我可以使用VBScript获取PowerLinestatus但是我如何获得程序监视(如TSR)状态并写入更改而不必将程序抛入循环?这就是我被困在的地方..如何保持程序运行以监控电源并仅在电源(电池或AC)发生变化时才写入?任何建议都将不胜感激。



问候,

Keith

Greetings:

I am new to VB script. I have learned a lot from this site as well as others. However I am having a problem with a concept for a script I would like to write and I need a push in the right direction.

First a little background. I have an old laptop with WinXP. I want to plug this laptop into an electrical outlet. When the power goes out I want my script to write to a file the time and date that the laptop ran off of the battery. When power is restored and the laptop is running off of ac current it will write in the same log file the time and date AC power was restored. I basically want to use this laptop to log power outages at my house while I''m away.

I can get the PowerLinestatus using VBScript but how do I get the program to monitor (like a TSR) the status and write the changes without having to throw the program in to a loop? This is where I am stuck at.. How to keep the program running to monitor the power and write only when there is a change is power source (battery or AC)? Any advice would be greatly appreciated.

Regards,
Keith

推荐答案

我不会为此寻找WMI解决方案。有一种非常直接的方法来处理这些事情:使用.NET FCL类 Microsoft.Win32.SystemEvents

http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx [ ^ ]。



你需要处理静态事件 Microsoft.Win32.SystemEvents.PowerModeChanged

http://msdn.microsoft.com/en-us/library /microsoft.win32.systemevents.powermodechanged.aspx [ ^ ]。



要随时轮询当前的电源状态,您可以使用<$ c $类C> System.Windows.Forms.SystemInformation :

http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.aspx [ ^ ]。



PowerStatus (属性和类)帮助页面上的代码示例演示了如何获取此信息:

http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation .powerstatus.aspx [ ^ ],

HTTP:// MSD n.microsoft.com/en-us/library/system.windows.forms.powerstatus.aspx [ ^ ]。



我希望它能帮到你需要。



-SA
I would not look for WMI solution for this. There is quite a straightforward way of handling such things: use the .NET FCL class Microsoft.Win32.SystemEvents:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx[^].

You will need to handle the static event Microsoft.Win32.SystemEvents.PowerModeChanged:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.powermodechanged.aspx[^].

To poll the current power status at any time, you can use the class System.Windows.Forms.SystemInformation:
http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.aspx[^].

The code samples on the help pages on PowerStatus (property and class) demonstrate how to get this information:
http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.powerstatus.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.powerstatus.aspx[^].

I hope it will get you all you need.

—SA


如果您真的想了解更多关于您可以在计算机上查看WMI:用于Windows Management Instrumentation的CIMTool - 第3部分 [ ^ ] - 它也有助于代码生成。



最好的问候

Espen Harlinn
If you really like to know more about the capabilities exposed by WMI on your computer, you could have a look at: CIMTool for Windows Management Instrumentation - Part 3[^] - it also helps with code generation.

Best regards
Espen Harlinn


这篇关于WMI和笔记本电池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆