Avatar billede neo2k Nybegynder
27. oktober 2003 - 15:16 Der er 8 kommentarer og
1 løsning

Shutdown.exe, hjemmelavet

Nogle der kan svare mig på hvordan man kan få en PC til at slukke, genstarte og logge af, jeg vil gerne selv lave programmet, men er på bar bund, ville gerne lave det som en konsol-applikation, ved dog næsten ingenting om Konsol-applikationer... HJÆLP :-)

NEO2k
Avatar billede borrisholt Novice
27. oktober 2003 - 15:29 #1
Avatar billede neo2k Nybegynder
27. oktober 2003 - 15:36 #2
Det er også fint, men jeg mangler et LILLE program, der bare skal have parametre, kender du sådan et???
Avatar billede borrisholt Novice
27. oktober 2003 - 15:39 #3
Næææ lav et selb .. Du skal bruge funktionen
function ExitWIndows( iFlags : integer ) : boolean;

  function SetPrivilege( sPrivilegeName : string; bEnabled : 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( sPrivilegeName ), TP.Privileges[ 0 ].LUID ) )then
      begin
      if( bEnabled )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
  Result := True;
  if( SetPrivilege( 'SeShutdownPrivilege', True ) )then
  begin
    if( not ExitWindowsEx( iFlags, 0 ) )then
    begin
      // handle errors...
      Result := False;
    end;
    SetPrivilege( 'SeShutdownPrivilege', False )
  end
  else
  begin
    // handle errors...
    Result := False;
  end;
end;


Jens B
Avatar billede neo2k Nybegynder
27. oktober 2003 - 15:48 #4
Hvad er iFlags???
Avatar billede borrisholt Novice
27. oktober 2003 - 15:55 #5
Hvis du vil

Lukke : EWX_SHUTDOWN
Genstarte : EWX_REBOOT
Log af :  EWX_LOGOFF

De ligger i windows.pas
Avatar billede neo2k Nybegynder
27. oktober 2003 - 15:55 #6
k, jeg er ikke så pro endnu, tak for hjælpen...

NEO2k
Avatar billede borrisholt Novice
27. oktober 2003 - 15:59 #7
Der er flere flag

I din delphi gå ind i hjælp-->Windows SDK

slå ExitWindowsEx op, og glem det der står om WinNt til sidst. Det har jeg taget hånd om:-)

Jens B
Avatar billede borrisholt Novice
27. oktober 2003 - 15:59 #8
EWX_FORCE    Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.

EWX_LOGOFF    Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.

EWX_POWEROFF    Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the

SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.

EWX_REBOOT    Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.

EWX_SHUTDOWN    Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
Avatar billede neo2k Nybegynder
27. oktober 2003 - 16:00 #9
OK, tak

NEO2k
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester