Link to home
Start Free TrialLog in
Avatar of perkster
perkster

asked on

Disable windows key (start menu key)

I need some coding so that I can disable the function of the windows (start menu) key.  Help.
ASKER CERTIFIED SOLUTION
Avatar of oumer
oumer

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 oumer
oumer

I found another api that can take care of only the start button. there is still some problem, now you can't click on the start menu, but still users can access it from the keyboard (using ctl+esc, or the microsoft button)

Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Public Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long

sub DisableEnableStartButton(flag as boolean)
 Dim result As Long
 result = FindWindowEx(0&, 0&, "Shell_TrayWnd",  vbNullString)
 result = FindWindowEx(result, 0&, "Button", vbNullString)
 EnableWindow result, NOT flag
end sub

as before, call it with true to disable the start button. To enable it , call it with false. When the key is disabled you see that it is greyed out. Actually the enable window api call is also used to enable/disable windows.

Please remember to call the enable the button after you test it.
Avatar of perkster

ASKER

I am getting "Argument not optional" when I run the suggestion submitted 02/04/2002 02:46PM PST.  I added the snippet to a module (is that correct) and the command portion to the form?  What am I doing wrong?

Thanks
IS it in the API call ( SystemParametersInfo SPI_SCREENSAVERRUNNING, 1&, 0&, 0 or the other one) that you are getting the error? Because I ran the code as it is and it works. And which version of VB are u using? If you could send me the line where the compiler complains and the exact error message, I will try to see what I can do.
I tried it with two cases:
1. everything in a form
here you have to put the declarations as private, and here is the whole code for the form:

Option Explicit
Private Const SPI_SCREENSAVERRUNNING = 97

Private Declare Function SystemParametersInfo Lib "user32" _
   Alias "SystemParametersInfoA" (ByVal uAction As _
   Long, ByVal uParam As Long, lpvParam As Any, ByVal _
   fuWinIni As Long) As Long


Sub DisableEnableKeys(flag As Boolean)

  If flag Then
    SystemParametersInfo SPI_SCREENSAVERRUNNING, 1&, 0&, 0
  Else
    SystemParametersInfo SPI_SCREENSAVERRUNNING, 0&, 0&, 0
  End If

End Sub



Private Sub Command1_Click()
DisableEnableKeys True
End Sub

Private Sub Command2_Click()
DisableEnableKeys False
End Sub

2. The api and constant declarations in a module. Here they have to be public since we want to use them from another form.

In a module:
Option Explicit
Public Const SPI_SCREENSAVERRUNNING = 97

Public Declare Function SystemParametersInfo Lib "user32" _
   Alias "SystemParametersInfoA" (ByVal uAction As _
   Long, ByVal uParam As Long, lpvParam As Any, ByVal _
   fuWinIni As Long) As Long

And in the form:

Sub DisableEnableKeys(flag As Boolean)

  If flag Then
    SystemParametersInfo SPI_SCREENSAVERRUNNING, 1&, 0&, 0
  Else
    SystemParametersInfo SPI_SCREENSAVERRUNNING, 0&, 0&, 0
  End If

End Sub

Private Sub Command1_Click()
DisableEnableKeys True
End Sub

Private Sub Command2_Click()
DisableEnableKeys False
End Sub

And both cases work and I am using vb6.


Good luck
Avatar of Richie_Simonetti
Hi,

  I tried both examples (and although I did not get an error), they did not prevent me from using the key-combo (Ctrl-alt-del, etc.) or the windows key.

  I am using VB6 on WinXP.

Any other advice.

R
For a reason that i don't know, you could disable Start button but it doesn't prevent it to receive keyboard strokes.
If a window is disabled, how it gets windows messages?
I am using vb6 on win98. And it works over here (with some extra side effects I mentioned in the comments). Sorry I couldn't be of help
I don't suppose we can see any movement in your many open questions?  For the record:

Questions Asked 5
Last 10 Grades Given A  
Question Grading Record 1 Answers Graded / 1 Answers Received

In case you so feel inclined, here is the list of your open questions:
Writing on to a CD -RW from Mac OS 8.6 Directly , is it possible ? Date: 11/21/2001 03:23AM PST
https://www.experts-exchange.com/jsp/qShow.jsp?ta=macintosh&qid=20238360
A simple query !! Date: 12/11/2001 11:00PM PST
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20245506
How to get rid of the startup programs ?? Date: 04/16/2002 06:21AM PST
https://www.experts-exchange.com/jsp/qShow.jsp?ta=winxp&qid=20290025

Anthony
Ignore the previous message it was posted in error.

Anthony