Board index » delphi » Trouble with windows shutdown/power off using D5
Dodgy
![]() Delphi Developer |
Sun, 30 Mar 2003 08:17:18 GMT
|
Dodgy
![]() Delphi Developer |
Sun, 30 Mar 2003 08:17:18 GMT
Trouble with windows shutdown/power off using D5
A friend asked me to write him something that turns his win98 machine
off after a set time... Easy I thought, and sent him a test form with a button containing.... He said it behaved like a logoff, and asked for a user name... I tried it on Windows 2000 (logged in as admin) and it does nothing at I then tried... But that didn't seem to do it either... Anyone got any ideas? Dodgy. |
Roy Rutte
![]() Delphi Developer |
Sun, 30 Mar 2003 03:00:00 GMT
Re:Trouble with windows shutdown/power off using D5Before making the call to ExitWindowsEx you should first call Application.Terminate. That should work. HTH, Roy Dodgy <Do...@uk.earth> schreef in berichtnieuws Quote> A friend asked me to write him something that turns his win98 machine |
Dodg
![]() Delphi Developer |
Sun, 30 Mar 2003 03:00:00 GMT
Re:Trouble with windows shutdown/power off using D5The logic of that completely escapes me! Surely with the app.terminate before the exitwindowsex call it will never execute it! Okay, I have now managed to get my friend to test with win98 and works great... Unfortunately windows 2000 just looks at me blankly! (well it ignores Dodgy. On Wed, 11 Oct 2000 14:01:08 +0200, "Roy Rutten" Quote>Before making the call to ExitWindowsEx you should first call |
Bj?rge S?the
![]() Delphi Developer |
Mon, 31 Mar 2003 07:14:29 GMT
Re:Trouble with windows shutdown/power off using D5"Dodgy" <Do...@uk.earth> skrev i melding news:bnv8usk12fm02hk9rd133puqe8juarq15r@4ax.com... Quote> The logic of that completely escapes me! procedure TApplication.Terminate; ..the PostQuitMessage call puts a WM_QUIT message in the message queue The point in program execution such messages will be processed, is the Quote> Okay, I have now managed to get my friend to test with win98 and permission to shut down the machine - have you tried with only ewx_logoff ? -- |
Roy Rutte
![]() Delphi Developer |
Mon, 31 Mar 2003 14:30:20 GMT
Re:Trouble with windows shutdown/power off using D5Quote> The logic of that completely escapes me! termination right away. The function posts a message which will be executed when the main thread in your programm is idle (so sometime after your ButtonClick handler has been executed). The same goes for ExitWindowsEx. So the correct order is to first terminate the application and then shutdown windows. Quote> Okay, I have now managed to get my friend to test with win98 and |
VBDi
![]() Delphi Developer |
Mon, 31 Mar 2003 03:00:00 GMT
Re:Trouble with windows shutdown/power off using D5Im Artikel <95c7usga5imu71ajvsq30fnvgvim7me...@4ax.com>, Dodgy <Do...@uk.earth> schreibt: Quote>ExitWindowsEx(EWX_POWEROFF,0); --- EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature. Windows NT/2000: The calling process must have the SE_SHUTDOWN_NAME privilege. --- Perhaps you have that privilege, as admin, but the process doesn't have it I also found: Since a poweroff always should be preceded by a shutdown, perhaps some DoDi |
David Rifki
![]() Delphi Developer |
Tue, 01 Apr 2003 11:04:45 GMT
Re:Trouble with windows shutdown/power off using D5QuoteOn Wed, 11 Oct 2000 01:17:18 +0100, Dodgy <Do...@uk.earth> wrote: TokenHandle: THandle; Privileges: TTokenPrivileges; begin if Win32Platform = VER_PLATFORM_WIN32_NT then begin Privileges.PrivilegeCount := 1; if not LookupPrivilegeValue('', 'SeShutdownPrivilege', Privileges.Privileges[0].Luid) then RaiseLastWin32Error; Privileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, TokenHandle) then RaiseLastWin32Error; try if not AdjustTokenPrivileges(TokenHandle, false, Privileges, 0, PTokenPrivileges(nil)^, PDWORD(nil)^) then RaiseLastWin32Error; finally CloseHandle(TokenHandle); end; end; if not ExitWindowsEx(EWX_POWEROFF, 0) then RaiseLastWin32Error; end; -- |
Dodg
![]() Delphi Developer |
Tue, 01 Apr 2003 14:49:16 GMT
Re:Trouble with windows shutdown/power off using D5D'oh! Me feel stupid now! Dodgy. On Thu, 12 Oct 2000 08:30:20 +0200, "Roy Rutten" Quote>> The logic of that completely escapes me! |
Dodg
![]() Delphi Developer |
Tue, 01 Apr 2003 14:49:17 GMT
Re:Trouble with windows shutdown/power off using D5I have had a play, and logoff works, so it's got to be this SE_SHUTDOWN_NAME bit.... A couple of questions.... Thanks in advance, Dodgy. On 12 Oct 2000 21:43:44 GMT, vb...@aol.com (VBDis) waffled on about Quote>Im Artikel <95c7usga5imu71ajvsq30fnvgvim7me...@4ax.com>, Dodgy <Do...@uk.earth> |
Dodg
![]() Delphi Developer |
Tue, 01 Apr 2003 03:00:00 GMT
Re:Trouble with windows shutdown/power off using D5Ohhh... What a lovely man! :o) That works a treat! Thanks David. On Fri, 13 Oct 2000 03:04:45 GMT, drifk...@acm.deleteme.org (David Quote>On Wed, 11 Oct 2000 01:17:18 +0100, Dodgy <Do...@uk.earth> wrote: |