Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-23-2012, 05:54 PM
Nenithe Nenithe is offline
Junior Member
 
Join Date: Sep 2011
Posts: 1
Default Hibernate

Hi !

I have one Question about activate hibernate from an application.

But i can't find anything about hibernate or any other sleep function,
please help me, I hate that I can't find any way out of this problem.

If Someone knows, i like to know, how to set the computer to Hibernate and sleep. And do this without asking like I use [EWX_FORCE] if it's possible ?
Thanks if someone can help me.

[Code I use following]


function togglecom(RebootParam: Longword): Boolean;
var
TTokenHd: THandle;
TTokenPvg: TTokenPrivileges;
cbtpPrevious: DWORD;
rTTokenPvg: TTokenPrivileges;
pcbtpPreviousRequired: DWORD;
tpResult: Boolean;
const
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
tpResult := OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
TTokenHd);
if tpResult then
begin
tpResult := LookupPrivilegeValue(nil,SE_SHUTDOWN_NAME,TTokenPv g.Privileges[0].Luid);
TTokenPvg.PrivilegeCount := 1;
TTokenPvg.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
cbtpPrevious := SizeOf(rTTokenPvg);
pcbtpPreviousRequired := 0;
if tpResult then
Windows.AdjustTokenPrivileges(TTokenHd,False,TToke nPvg,cbtpPrevious,rTTokenPvg,pcbtpPreviousRequired );

end;
end;
Result := ExitWindowsEx(RebootParam, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
togglecom(EWX_POWEROFF or EWX_FORCE);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
togglecom(EWX_REBOOT or EWX_FORCE);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
togglecom(EWX_LOGOFF or EWX_FORCE);
end;
Reply With Quote
  #2  
Old 01-24-2012, 04:52 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 4,764
Default

Try: http://www.swissdelphicenter.ch/en/showcode.php?id=168
__________________
Regards,
Abdulaziz Jasser
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:38 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.