Link to home
Start Free TrialLog in
Avatar of Dide
Dide

asked on

Disable shutdown and LogOff but Start Button Enable

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 ?
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tyfing
tyfing

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.
Avatar of Dide

ASKER

I tried your comments but my windows can logoff and shuting down
you may need to restart windows before the reg tweaks will work.
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.
Avatar of Dide

ASKER

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 ?
Avatar of Dide

ASKER

ups...sorry

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

ASKER

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;

Avatar of Dide

ASKER

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;
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.
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