On pre-vista strong> systems, you can request the Registry :
The shutdown setting DWORD found in HKCU\Software\Microsoft\Windows\CurrentVersion\Explorersaves the last selected one from the list in the "Shut Down Windows" dialog box for the current user.
On later systems, you can query the System event log in your disconnect script, for example:
$systemstateentry = get-eventlog -LogName system -Source User32 | ?{$_.eventid -eq 1074} | select -first 1
switch -regex ($systemstateentry.message)
{
".*restart.*" {"restart"}
".*power off.*" {"power off"}
default {"unknown"}
}
jon Z source
share