comp.lang.ada
 help / color / mirror / Atom feed
* Problem with Win32Ada - Shutdown NT/Win2k
@ 2002-07-12 17:32 Bj�rn Holmberg
  0 siblings, 0 replies; only message in thread
From: Bj�rn Holmberg @ 2002-07-12 17:32 UTC (permalink / 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.




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-07-12 17:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-12 17:32 Problem with Win32Ada - Shutdown NT/Win2k Bj�rn Holmberg

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