comp.lang.ada
 help / color / mirror / Atom feed
From: Bj�rn Holmberg <bjornholmberg@bredband.net>
Subject: Problem with Win32Ada - Shutdown NT/Win2k
Date: Fri, 12 Jul 2002 19:32:11 +0200
Date: 2002-07-12T19:32:11+02:00	[thread overview]
Message-ID: <m23uiu0irvep8f1i8dlbh6r2a0sbvoclhc@4ax.com> (raw)

I need to shut down a Win NT machine, but I can't seem to get it
right. The function Lookupprivilegevalue returns me zero. I'm not
familiar with the API and I'm having a hard time figure out how to
handle the pointers.

This is what I have so far:

with Win32.Winbase;
with Win32.Winnt;
with System;
with Ada.Unchecked_Conversion;
with Text_Io;

procedure Shut_Down is 
   Returned_Ok  : Win32.Bool;
   Luid         : Win32.Winnt.Luid := (Which => Win32.Winnt.U_Kind, U
=> (Lowpart => 0, Highpart => 0));
   PLuid        : Win32.Winnt.Pluid; -- ????
   TP           : Win32.Winnt.Ptoken_Privileges; 
   Htoken       : Win32.Winnt.Phandle := new Win32.Winnt.Handle;
           
   function CP(C_Str : Win32.CHAR_Array) return Win32.LPCSTR is
      function UC is new Ada.Unchecked_Conversion
                             (System.Address,Win32.LPCSTR);
   begin
      return UC(C_Str(C_Str'First)'Address);
   end Cp;
  
begin

   TP := new Win32.Winnt.Token_Privileges;
   TP.Privilegecount := 1;
   TP.Privileges(0).Luid := Luid;
   TP.Privileges(0).Attributes := 4;

   Returned_Ok :=
Win32.Winbase.Openprocesstoken(Win32.Winbase.Getcurrentprocess,Win32.Winnt.Token_Adjust_Privileges
or Win32.Winnt.Token_Query, hToken);
   Text_Io.Put_Line("The function returned = " &
Win32.Bool'Image(Returned_OK));
   Returned_Ok :=
Win32.Winbase.Lookupprivilegevalue(null,CP(Win32.Winnt.Se_Shutdown_Name),
PLuid);
   Text_Io.Put_Line("The function returned = " &
Win32.Bool'Image(Returned_OK));
   --Returned_Ok :=
Win32.Winbase.Adjusttokenprivileges(Basse,Punk,0,null,Frase'access);
   --Returned_Ok := Win32.Winreg.Initiatesystemshutdown(null, null, 1,
Win32.Bool(1), Win32.Bool(1));

end Shut_Down ;


All suggestions would be appreciated.

TIA
Bj�rn.




                 reply	other threads:[~2002-07-12 17:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox