计算机电源使用类型检测程序
在上一篇文章《安装XP SP3发现的小功能》中,看到微软的SP3在安装的时候对所使用的电源进行了检测,感觉这样的功能具有一定的实用意义。因为以前没接触地电源管理方面的知识,在最我提到要了解一下,这一功能是怎么实现的,就有了此文。呵呵。用ASM写的代码比较简单,就要就是微软提供了GetSystemPowerStatus这个检测电源状态的API。
程序代码和可执行文件打包下载:
powertest.zip (1.7 KiB, 399 hits)
程序运行如下:

;********************************************
;Target:
;检测系统所使用的电源类型,是直流还是交流电源
;Author: Lonkil lonkil_at_Gmail.com
;Site: WWW.VCFANS.COM
;Date: 2008-6-14
;********************************************
.386
.model flat,stdcall
option casemap:none
include windows.inc
include Kernel32.inc
include gdi32.inc
include user32.inc
includelib kernel32.lib
includelib gdi32.lib
includelib user32.lib
.data
szTitle db “检测系统所用电源类型 Code By Lonkil Www.Vcfans.Com ”, 0
szDC db “你的系统使用直流电源供电”, 0
szAC db “你的系统使用交流电源供电”, 0
szOther db “你的系统使用未知电源供电”, 0
szError db “对不起,调用检测程序出错,无法检测您所使用的电源类型。”, 0
.data?
sps SYSTEM_POWER_STATUS <?>
.code
start:
invoke RtlZeroMemory,offset sps,sizeof SYSTEM_POWER_STATUS
invoke GetSystemPowerStatus,offset sps
.if eax == 0
;failed GetSystemPowerStatus
invoke MessageBox, 0 , offset szError, offset szTitle , MB_ICONERROR
.else
;Success SYSTEM_POWER_STATUS
mov al, sps.ACLineStatus
.if al == 0
invoke MessageBox, 0, offset szDC, offset szTitle, MB_ICONINFORMATION
.elseif al == 1
invoke MessageBox, 0, offset szAC, offset szTitle, MB_ICONINFORMATION
.else
invoke MessageBox, 0, offset szOther, offset szTitle, MB_ICONINFORMATION
.endif
.endif
invoke ExitProcess, NULL
end start