Sign in to follow this  
Followers 0
kosamja

Disable Windows Explorer context menu items?

3 posts in this topic

#1 ·  Posted (edited)

I tried this, but it doesnt disable Toolbars, View, Sort by, Group by...

; www.autoitscript.com/forum/topic/124460-how-to-disable-context-menu-item-in-windows-7/

#NoTrayIcon
#Include <SendMessage.au3>
#include <File.au3>

Opt("SendKeyDelay", 0) ;
Opt("SendKeyDownDelay", 0) ;
Opt("WinWaitDelay", 0) ;
Local $iCountLines = _FileCountLines("Disable.txt")

Global Const $MF_BYPOSITION = 0x0400
Global Const $MF_GRAYED = 0x1

while 1

    $wnd = WinWait('[CLASS:#32768]')
    $hwnd = _SendMessage($wnd, 0x01E1)
    $MenuCount = GetMenuItemCount($hwnd)
    Local $i = 0
    Do
        $i = $i + 1
        Local $itemtext = FileReadLine("Disable.txt", $i)
    For $x = 0 To $MenuCount
        $text = _GUICtrlMenuGetString($hwnd, GetMenuItemID($hwnd, $x))
        IF StringReplace($text, '&', '') == $itemtext Then DllCall("User32.dll", "Int", "EnableMenuItem", "HWND", $hwnd, "UInt", $x, "UInt", BitOR($MF_BYPOSITION, $MF_GRAYED))
    Next
 Until $i = $iCountLines

WEnd

Func GetMenuItemCount($hMenu)
    Local $nCount = DllCall('user32.dll', "int", "GetMenuItemCount", "hwnd", $hMenu)
    Return $nCount[0]
EndFunc

Func GetMenuItemID($hMenu, $nPos)
    Local $nID = DllCall('user32.dll', "int", "GetMenuItemID", "hwnd", $hMenu, "int", $nPos)
    Return $nID[0]
EndFunc

;http://my-autoit.googlecode.com/svn-history/r29/trunk/Scripts/MkCabSFX/Includes/GuiMenu1.au3
Func _GUICtrlMenuGetString($GMS_hWnd, $GMS_id, $GMS_Opt=0)
  If $GMS_hWnd <= 0 Or $GMS_id < 0 Then Return 0
  Local $MF_BYCOMMAND = 0x00000000
  Local $MF_BYPOSITION = 0x00000400
  If $GMS_Opt = 0 Then
     $GMS_Opt = $MF_BYCOMMAND
  Else
     $GMS_Opt = $MF_BYPOSITION
  EndIf
  Local $GMS_r = DllCall("user32.dll","int","GetMenuString", _
                   "hwnd",$GMS_hWnd, _
                   "int",$GMS_id, _
                   "str","","int",0, _
                   "int",$GMS_Opt)
  If @error Then Return 0
  $GMS_r = DllCall("user32.dll","int","GetMenuString", _
                   "hwnd",$GMS_hWnd, _
                   "int",$GMS_id, _
                   "str","","int",$GMS_r[0]+1, _
                   "int",$GMS_Opt)
  If @error Then Return 0
  Return $GMS_r[3]
EndFunc

Disable Context Menu Items.au3

Disable.txt

Edited by kosamja

Share this post


Link to post
Share on other sites



what example should i see on that link? any idea what in script i use should be changed so that it also disables windows explorer context menu items that have submenus?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0