Mirror

How to disable and reenable the Windows start button (Views: 100)


Problem/Question/Abstract:

How can I disable the Windows start button and prevent the user from accessing it by clicking on it or by pressing [CTRL] + [ESC] ?

Answer:

Solve 1:

To disable the Start button:

var
  h: hwnd;
begin
  h := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil);
  EnableWindow(h, false);
end;

But the user can still access the start menu by pressing [CTL] + [ESC] or the windows key. Even hiding the Start button doesn't work. But hiding the Start button and using the SetParent function seems to work:

var
  h: hwnd;
begin
  h := FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil)
    ShowWindow(h, 0);
  Windows.SetParent(h, 0);
end;

To enable the Start button again:

var
  h: hwnd;
  TaskWindow: hwnd;
begin
  h := FindWindowEx(GetDesktopWindow, 0, 'Button', nil);
  TaskWindow := FindWindow('Shell_TrayWnd', nil);
  Windows.SetParent(h, TaskWindow);
  ShowWindow(h, 1);
end;

Furthermore, you could create your own Start button and "replace" it with your own.

var
  b: TButton; {or another button type that can hold a bitmap}
  h, Window: hwnd;
begin
  Window := FindWindow('Shell_TrayWnd', nil);
  b := TButton.Create(nil);
  b.ParentWindow := Window;
  b.Caption := 'Start';
  b.Width := 60;
  b.font.style := [fsbold];
end;


Solve 2:

procedure TForm1.Button1Click(Sender: TObject);
var
  Rgn: hRgn;
begin
  {Hide the start button}
  Rgn := CreateRectRgn(0, 0, 0, 0);
  SetWindowRgn(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil), Rgn,
    true);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  {Turn the start button back on}
  SetWindowRgn(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil), 0,
    true);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  {Disable the start button}
  EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil),
    false);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  {Enable the start button}
  EnableWindow(FindWindowEx(FindWindow('Shell_TrayWnd', nil), 0, 'Button', nil),
    true);
end;

<< Back to main page