We help IT Professionals succeed at work.

Disable shutdown and LogOff but Start Button Enable

Dide
Dide asked
on
I Wrote this code
EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd'_nil),0,'Button',nil),FALSE);

this code to disable button start Win9x, How if I want just disable shutdown and log off function ? but
start button and others are enable ?
Comment
Watch Question

Commented:
you can disable the shutdown by adding a policy to the registry under

HKCU/software/microsoft/windows NT/currentversion/policies/explorer/
ad a new DWORD called NoClose and set to 1 or 0 to disable or enable the shutdown.

other way is to have a service or program that is catching the WM_QueryEndSession message()

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
   procedure WMQueryEndSession(var Msg: TWMQueryEndSession) ; message WM_QUERYENDSESSION ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ok_to_close : boolean;

implementation

{$R *.DFM}

procedure TForm1.WMQueryEndSession(var Msg: TWMQueryEndSession);
const
  CAN_SHUTDOWN = 0 ;
  DONT_SHUTDOWN = 1 ;
begin
  inherited ;
  if ok_to_close then {ok_to_close is the global boolean}
  Msg.Result := CAN_SHUTDOWN
  else {if ok_to_close has been set to false then we would get here}
    Msg.Result := DONT_SHUTDOWN ;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ok_to_close := false;
end;

Commented:
u can simply add a registry entry to disable the Shutdown and Log-off
HKCU\software\microsoft\windows\currentversion\policies\explorer

add in
NoClose and put its value to 1 to disable Shutdown
NoLogoff and put its value to 1 to disable Log-off

source is below

Var
reg:tregistry;
begin
reg.create;
reg.rootkey:=HKEY_Current_User;
reg.openkey('software\microsoft\windows\currentversion\policies\explorer');
reg.writestring('NoClose', '1'); // This disables Shutdown, you can change it to NoLogoff to disable Log-off.
end;
end.

Author

Commented:
I tried your comments but my windows can logoff and shuting down

Commented:
you may need to restart windows before the reg tweaks will work.

Commented:
HI,
Tyfing, in your code there are two errors:
1.reg:=TRegistry.Create, not reg.Create;
2.OpenKey has two parameters not one.
Maybe that is why Dide failed in using your proposal.
Sincerely,
Nestorua.

Author

Commented:
Yes these errors, but I wrote :
Var
reg:Tregistry;
const
a='NoClose';
begin
reg:=TRegistry.create;
reg.rootkey:=HKEY_Current_User;
reg.openkey('software\microsoft\windows\currentversion\policies\explorer',False);
reg.writestring(a, '1');
end;
end.

but it's wrong still
I try this write yhis code on event create form
procedure TFormX.Create.....;
Const
MyWM_NotifyIcon=WM_USER+
Var
IC:NOTIFYICONDATA;
HOwner:HWND;
Begin
 HOwner:GetWindow(FormX.Handle,GW_OWNER;
 ic.cbsize:=size of(NOTIFYICONDATA);
 ic.Wnd:=FormX.Handle;
 ic.UID:=13598056;
 ic.UCallBackMessage:=MyWM_Notifyicon;
 ic.hicon:=Application.icon.Handle;
 ic.UFlags:=NIF_ICON or NIFMESSAGE or NIF_TIP;
end;
 
these code solve my problem but I don't Understand with these code, anyone can  explain to me ?

Author

Commented:
ups...sorry

....
I try  write this code on event create form
.....
MyWM_NotifyIcon=WM_USER + 1234;
.......

Author

Commented:
When a user shutdown windows, The onCloseQuery event is activated, and a program can use it to stop the shutdown process

so we can stop shutdown process with the set onCloseQuery event :
CanClose:=False;

Author

Commented:
I Have the answer

When a user shutdown windows, The onCloseQuery event is activated, and a program can use it to stop the shutdown process

so we can stop shutdown process with the set onCloseQuery event :
CanClose:=False;

Commented:
Var
reg:tregistry;
begin
reg.create;
reg.rootkey:=HKEY_Current_User;
reg.createkey('software\microsoft\currentversion\policies\explorer');
reg.openkey('software\microsoft\windows\currentversion\policies\explorer', TRUE);
reg.writestring('NoClose', '1'); // This disables Shutdown, you can change it to NoLogoff to disable Log-off.
REG.CLOSEKEY;
end;
end.
Dide:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
CERTIFIED EXPERT

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

accept inthe's comment as answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Thanks,

geobul
EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.