Figured I'd add my 2 cents' worth to this thread...
I recently added an APC SmartUPS to a test position and attached it via USB. I started with Phil Brooks approach - registering a callback VI to catch the Microsoft.win32.SystemEvents.SystemPowerChanged event., then within the callback VI I call GetSystemPowerStatus from kernel32.dll. I then post a LV user event with the info I retrieve. This makes it easy to manage power events from a LV event structure which could be handling lots of other activity.
I developed and tested my code on my laptop, which doesn't have an external UPS, but when I connected and disconnected mains power it worked quite well and reported laptop battery remaining, etc.
Things I found out:
Make sure you have the .NET Framework 2.0 installed on the target computer. Otherwise, the .NET event registration fails.
The code worked correctly on the target system *until* I installed the APC PowerChute Business Edition Agent 7.04. The Agent apparently disables the Windows native UPS support, after which the .NET events stop firing. I uninstalled the PowerChute drivers and got it to work again. In my case, I can live without the Agent, though it would've been nice for the remote monitoring and logging features.
I don't know if this problem is peculiar to APC - I would like to think that any vendor's UPS miniport driver would continue to support the Windows-generic SystemPowerChanged interface.
Best regards,
Dave
David Boyd
Sr. Test Engineer
Abbott Labs
(lapsed) Certified LabVIEW Developer