Jump to content

Recommended Posts

I have disabled the desktop context menu by editing the "Registry".  It requires a computer restart.  A mouse right click then shows no menu.  Below is my code to do this in a script.

$key3 = "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer"
$val3 = "NoViewContextMenu"
$ContextMenu = RegRead($key3, $val3)   ; Save  0 = Menu is available
$ctxMenu = 1

RegWrite($key3, $val3, "REG_DWORD", $ctxMenu)   ; 1 = Menu is not available

; Do something here

; Restore to previous

RegWrite($key3, $val3, "REG_DWORD", $ContextMenu)   ; 0 = Menu now available

Is there a DLLCALL function to set the parameters to do this?

I have modified "wallpaper" setting in similar code.  However, there was DLL example found in the forums.  Is there a list out there of all DLL functions?  I found partial list.  Most of the information was about modifying the context menu.

Link to post
Share on other sites

I'm failing to find a DLL or API call to do this.  It does appear though that just restarting Explorer.exe takes care of it, in lieu of a full reboot.

Link to post
Share on other sites


Run("explorer.exe", "", @SW_HIDE) doesn't hide the window and the context menu remains after setting the RegWrite  to "1" 

Is this a possible candidate for a new function?  My work around is to create a full screen invisible window where a mouse right click prevents the desktop context menu from appearing.  I use right click to do other things and I don't want the menu to keep popping up.

Link to post
Share on other sites

@BackHomeAgain What I meant was is if you set the NoViewContextMenu value to 1, then terminate and restart explorer.exe (no need for @SW_HIDE), than the context menu is disabled.  

I like the way @Nine thinks.  If the intent is just to temporarily block the Desktop contextmenu, then hooking could be an ideal solution.

Link to post
Share on other sites

There is a way to do what you want, without having to close the session or the explorer, through the Local Group Policies

The Local Group Policies are stored in .pol format. The good new is that Microsoft provides a command line tool called "LGPO.EXE", which can interact with this kind of file.

  1. Download LGPO.exe : https://www.microsoft.com/en-us/download/details.aspx?id=55319 (LGPO.zip)
  2. Create a NoViewContextMenu.txt file, as indicated bellow 
  3. Build a policy file from the text file, using the following command : LGPO.exe /r NoViewContextMenu.txt /w NoViewContextMenu.pol
  4. Import the policy in the Local Group Policy (it's a user policy, so use /u) with that command : LGPO.exe /u NoViewContextMenu.pol (you will need Admin rights)
  5. That's all. The next step is to automate it using AutoIt (the steps 1 to 3 have to be done just one time)


; Disable the context menu

Warning : since the Home edition of Windows does not support the Local Group Policy editor, I don't know if it works with this tool 


Edit : I didn't try to execute the script using a different account, but in this case you will probably need to execute the gpupdate command  to apply the change

Edited by jguinch
Link to post
Share on other sites
On 1/19/2022 at 10:53 PM, BackHomeAgain said:

I use right click to do other things and I don't want the menu to keep popping up.

You can probably close them menus on the fly before you continue "things"

ControlSend("Program Manager", "", "[CLASS:SysListView32; INSTANCE:1]", "{RCTRL}{ALT}")


Link to post
Share on other sites
  • 2 weeks later...

The following works for me.

;Create full screen window to block desktop context menu.
;The "1" in WinSetTrans function is important. Also hides the task bar.
;The right mouse click is used to pause and continue the script.
;Left mouse click stops the script and all settings restored.

$hGUI = GUICreate("", @DesktopWidth+10, @DesktopHeight+10, -1, -1, 0x80000000)
WinSetTrans($hGUI, "", 1)  ;Make window invisible.

The GUI is deleted and the screen is back to normal. 

Link to post
Share on other sites
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...