转载:<br>function GetWinVersion: String;<br> var<br> VersionInfo : TOSVersionInfo;<br> OSName : String;<br> begin<br> // set the size of the record<br> VersionInfo.dwOSVersionInfoSize := SizeOf( TOSVersionInfo );<br> <br> if Windows.GetVersionEx( VersionInfo ) then<br> begin<br> with VersionInfo do<br> begin<br> case dwPlatformId of<br> VER_PLATFORM_WIN32s : OSName := 'Win32s';<br> VER_PLATFORM_WIN32_WINDOWS : OSName := 'Windows 95';<br> VER_PLATFORM_WIN32_NT : OSName := 'Windows NT';<br> end; // case dwPlatformId<br> Result := OSName + ' Version ' + IntToStr( dwMajorVersion ) + '.' + IntToStr( dwMinorVersion ) +<br> #13#10' (Build ' + IntToStr( dwBuildNumber ) + ': ' + szCSDVersion + ')';<br> end; // with VersionInfo<br> end // if GetVersionEx<br> else<br> Result := '';<br> end;<br> <br> procedure ShutDown;<br> const<br> SE_SHUTDOWN_NAME = 'SeShutdownPrivilege'; // Borland forgot this declaration<br> var<br> hToken : THandle;<br> tkp : TTokenPrivileges;<br> tkpo : TTokenPrivileges;<br> zero : DWORD;<br> begin<br> if Pos( 'Windows NT', GetWinVersion) = 1 then // we've got to do a whole buch of things<br> begin<br> zero := 0;<br> if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br> begin<br> MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br> Exit;<br> end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br> if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken) then<br> begin<br> MessageBox( 0, 'Exit Error', 'OpenProcessToken() Failed', MB_OK );<br> Exit;<br> end; // if not OpenProcessToken( GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)<br> <br> <br> // SE_SHUTDOWN_NAME<br> if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[ 0 ].Luid ) then<br> begin<br> MessageBox( 0, 'Exit Error', 'LookupPrivilegeValue() Failed', MB_OK );<br> Exit;<br> end; // if not LookupPrivilegeValue( nil, 'SeShutdownPrivilege' , tkp.Privileges[0].Luid )<br> tkp.PrivilegeCount := 1;<br> tkp.Privileges[ 0 ].Attributes := SE_PRIVILEGE_ENABLED;<br> <br> AdjustTokenPrivileges( hToken, False, tkp, SizeOf( TTokenPrivileges ), tkpo, zero );<br> if Boolean( GetLastError() ) then<br> begin<br> MessageBox( 0, 'Exit Error', 'AdjustTokenPrivileges() Failed', MB_OK );<br> Exit;<br> end // if Boolean( GetLastError() )<br> else<br> ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );<br> end // if OSVersion = 'Windows NT'<br> else<br> begin // just shut the machine down<br> ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );<br> end; // else<br> end;<br>