Fórum Em vez de desligar o PC faz logon, onde eu errei ? #165577
19/06/2003
0
Estou testando um programinha onde ira desligar o Pc em uma certa hora, porem inves de desligar o computador programa esta fazendo logon o codigo e :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Mask;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
MaskEdit1: TMaskEdit;
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption := TimeToStr(now);
if Label1.Caption = Trim(MaskEdit1.Text) then
Begin
//ShowMessage(´OK´);
Form1.Close;
end
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
const
EWX_POWEROFF = 8; // Desliga o equipamento
begin
ExitWindowsEx(EWX_POWEROFF,8);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Mask;
type
TForm1 = class(TForm)
Timer1: TTimer;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
MaskEdit1: TMaskEdit;
procedure Timer1Timer(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption := TimeToStr(now);
if Label1.Caption = Trim(MaskEdit1.Text) then
Begin
//ShowMessage(´OK´);
Form1.Close;
end
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
const
EWX_POWEROFF = 8; // Desliga o equipamento
begin
ExitWindowsEx(EWX_POWEROFF,8);
end;
end.
Kanedasam
Curtir tópico
+ 0
Responder
Posts
19/06/2003
Hebert
Isso aconteceu comigo com o Windows 2000.
Se o seu Windows eh 2000, utilize esse codigo:
Se o seu Windows eh 2000, utilize esse codigo:
Use-a assim: WinExit(EWX_SHUTDOWN or EWX_FORCE); function WinExit(flags: integer): boolean; function SetPrivilege(privilegeName: string; enable: boolean): boolean; var tpPrev, tp : TTokenPrivileges; token : THandle; dwRetLen : DWord; begin result := False; OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, token); tp.PrivilegeCount := 1; if LookupPrivilegeValue(nil, pchar(privilegeName), tp.Privileges[0].LUID) then begin if enable then tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED else tp.Privileges[0].Attributes := 0; dwRetLen := 0; result := AdjustTokenPrivileges(token, False, tp, SizeOf(tpPrev), tpPrev, dwRetLen); end; CloseHandle(token); end; begin if SetPrivilege(´SeShutdownPrivilege´, true) then begin ExitWindowsEx(flags, 0); SetPrivilege(´SeShutdownPrivilege´, False) end; end;
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)