Tuesday, March 15, 2011

create software with Delphi 7,, so that the computer / laptop shutdown automatically by determining the time

This simple software allows you to turn off the computer automatically by setting the time we give,,, for example by entering the number 3, then the computer turns off for 3 minutes ...
ok,, this time we will discuss how to make this software, using programming languages ​​delphi7 ..



   now, create a form like the image below


the picture above using
--->2 button button
--->An edit text
--->First timer

and other features that may I add just for variety,,, hehehe .....
but the point is, know the program to shut down the computer by setting time, ..

First, typing this program .. ..

---------------------------------------------------------------------------------------------------------- 
setShutDownPrivilege function: Boolean;
var
     TTokenHnd: THandle;
     TTokenPvg: TTokenPrivileges;
     cbtpPrevious: DWORD;
     rTTokenPvg: TTokenPrivileges;
     pcbtpPreviousRequired: DWORD;
     tpResult: Boolean;

const
     SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
begin
   Result: = false;

   if Win32Platform = VER_PLATFORM_WIN32_NT then
     begin
       if OpenProcessToken (GetCurrentProcess (), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, TTokenHnd) then
         begin
           tpResult: = lookupPrivilegeValue (nil, SE_SHUTDOWN_NAME, TTokenPvg.Privileges [0]. Luid);
           TTokenPvg.PrivilegeCount: = 1;
           TTokenPvg.Privileges [0]. Attributes: = SE_PRIVILEGE_ENABLED;
           cbtpPrevious: = sizeof (rTTokenPvg);
           pcbtpPreviousRequired: = 0;
           then if tpResult
             Result: = windows.AdjustTokenPrivileges (TTokenHnd, False, TTokenPvg, cbtpPrevious, rTTokenPvg, pcbtpPreviousRequired);
         end;
     end;
end;

function Power (pwFlags: Cardinal): Boolean;
begin
   if Win32Platform = VER_PLATFORM_WIN32_NT then
     setShutDownPrivilege;
     Result: = ExitWindowsEx (pwFlags, 0);
end;
program listings for button1 (active) ..
procedure TForm1.Button1Click (Sender: TObject);
var
   time: integer;
begin
if edit1.text =''then
begin
application.MessageBox ('enter a sleep timer on off time', 'information', mb_iconinformation);
edit1.SetFocus;
end
else
begin
time: = strtoint (edit1.text) * 60 000;
off.Interval: = time;
off.Enabled: = true;
button1.Enabled: = false;
edit1.Enabled: = false;
edit1.Color: = clmenubar;
WindowState: = wsMinimized;
end;
end;

---------------------------------------------------------------------------------------------------------- 
 
 
program listings for Timer1 ...
---------------------------------------------------------------------------------------------------------- 
procedure TForm1.offTimer(Sender: TObject);
begin

Power (EWX_SHUTDOWN or EWX_FORCE);
end;
 
---------------------------------------------------------------------------------------------------------- 

 
program listings for button 2 (Cancel)
---------------------------------------------------------------------------------------------------------- 
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Enabled:=true;
edit1.Color:=clwindow;
off.Enabled:=false;
edit1.SetFocus;
edit1.Text:='';
button1.Enabled:=true;

end; 

---------------------------------------------------------------------------------------------------------- 



or if you want to just try .. please download the
http://www.ziddu.com/download/14198761/Sleep_Timer.exe.html
 
good luck.......................... 

No comments:

Post a Comment