Código
function ShutDownWindows(Opcao: Byte):Boolean;
var
hToken : THandle;
pPrivileges : TTokenPrivileges;
pOldPrivileges: TTokenPrivileges;
Zero: DWord;
ptZero: DWord;
tResult: Boolean;
begin
//Checa a versão do Windows
//Se é NT/2000/XP então
//Ajusta os direitos
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
tResult := OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken);
if tResult then
tResult := LookupPrivilegeValue(nil, 'SeShutdownPrivilege', pPrivileges.Privileges[0].Luid);
pPrivileges.PrivilegeCount := 1;
pPrivileges.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
Zero := 0;
ptZero := SizeOf(pOldPrivileges);
if tResult then
Windows.AdjustTokenPrivileges(hToken,
False,
pPrivileges,
ptZero,
pOldPrivileges,
Zero);
end;
case Opcao of
//Desliga
0: begin
Result := ExitWindowsEx(EWX_SHUTDOWN or EWX_FORCE, 0);
end;
//Reinicia
1: begin
Result := ExitWindowsEx(EWX_REBOOT or EWX_FORCE, 0);
end;
//LogOff do usuário atual
2: begin
Result := ExitWindowsEx(EWX_LOGOFF or EWX_FORCE, 0);
end;
//Desliga, mas o sistema precisa ter o recurso de Power-Off
3: begin
Result := ExitWindowsEx(EWX_POWEROFF or EWX_FORCE, 0);
end;
else begin
Result := False;
Exit;
end;
end;
end;
//Agora no onclick vc coloca:
ShutDownWindows(3);
//onde:
//1: Reinicia;
//2: Efetua LogOff;
//3: desliga;
{So nao coloquei a autoria pq nao lembro de onde copiei o codigo, muito menos do autor, mas sou muto grato a ele :D}
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009