Hi Mike-
We used an APC 600W UPS with a serial link to the PC. We went through a BIG hassle with APC to get them to disclose their communications API to the UPS - normally they want you to use their canned software to implement shutdown in the event of power fail. As it was, we simply monitor the serial port for any incoming character, and on receipt of any incoming character from the UPS, we start a shutdown.
Programmatic shutdown of apps and NT itself are described in the Win32 SDK that comes with the CVI Full Scale Development System (FDS).
We sized the UPS to provide power to the PC as well as a couple of instruments in the system. Our goal was to save off data to hard disk and then do an orderly shutdown.
You have to enabl
e shutdown privledges in NT:
// Get a pseudo-handle to this process.
hProcess = GetCurrentProcess ();
// Enable NT shutdown privilege for this process.
OpenProcessToken (hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
LookupPrivilegeValue (NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges (hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES) NULL, 0);
Then to do a shutdown of all apps (forced) and then shut down NT:
InitiateSystemShutdown (NULL, // address of name of computer to shut down
NULL, // address of message to display in dialog box
0, // time to display dialog box
TRUE, // force applications with unsaved changes flag
FALSE // reboot flag.
);
You can
also install a main window callback in your app to recieve the Win32 "EVENT_END_TASK" message from NT sent to all apps when the system is shutting down.
Bob Hayes