As for detecting if the system is shutting down, that one is a little more tricky. Maybe hooking InitiateShutdown()?: http://msdn.microsoft.com/en-us/library/windows/desktop/aa376872(v=vs.85).aspx But the correct way to do this is probably to disable shutdown privileges through a GPO. What are you trying to do exactly?
Who the heck are you to tell the user he can't shut down his system? (Even if it is your own system.)
Better way is to respond to shutdown signal, save program state and add self to autorun once registry key. When system comes back up, so does your program with state preserved. Calculations may continue, etc.
Get SystemMetrics is a terrible solution since you'll have to constantly run it in a loop. I'll ask again, because I truly believe there is a better way, What is it you are trying to do exactly?
EDIT: I told you how to abort the shutdown. The function is "AbortSystemShutdown()". I may have posted it a little funny but if you had clicked the link I gave you, you would have seen it.
BOOL PreventSystemShutdown()
{
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
// Get the current process token handle so we can get shutdown
// privilege.
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
return FALSE;
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
return FALSE;
// Prevent the system from shutting down.
if ( !AbortSystemShutdown(NULL) )
return FALSE;
// Disable shutdown privilege.
tkp.Privileges[0].Attributes = 0;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
return TRUE;
}