Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change the right click context menu for Windows batch *.bat files

272 views
Skip to first unread message

John Robertson

unread,
Jul 3, 2022, 10:40:26 AM7/3/22
to
Is there a way to change the right click context menu for Windows *.bat
batch files to limit the options to just those that I want there?

I don't want open or open with.
I don't want print (as I can print from the editor)
I don't want Scan with Microsoft Defender...
I don't want share
I don't want Restore previous versions
I don't want send to

All I do want is what I do with a batch file.
For example, I definitely want the "Run as administrator" item
And I only need "Edit" and not print (because I can print from the editor)
I'm ok with the "Send to" section (but which I never use)
I'm ok with the "cut & copy" section too
I'm ok with the "Create shortcut, deleted, and rename" section
And I'm ok with the "Properties" section

That's it.
Is there a way to change the batch context menu to do just want I want it
to do? (Mostly just "Run as Administrator" and not much else.

--
(Please post followups or tech inquiries to the USENET newsgroup)
John's Jukes Ltd.
MOVED to #7 - 3979 Marine Way, Burnaby, BC, Canada V5J 5E3
(604)872-5757 (Pinballs, Jukes, Video Games)
www.flippers.com
"Old pinballers never die, they just flip out."

Stan Brown

unread,
Jul 3, 2022, 12:01:25 PM7/3/22
to
On Sun, 3 Jul 2022 08:40:49 -0600, John Robertson wrote:
>
> Is there a way to change the right click context menu for Windows *.bat
> batch files to limit the options to just those that I want there?
>
> I don't want open or open with.
> I don't want print (as I can print from the editor)
> I don't want Scan with Microsoft Defender...
> I don't want share
> I don't want Restore previous versions
> I don't want send to
>
> All I do want is what I do with a batch file.
> For example, I definitely want the "Run as administrator" item
> And I only need "Edit" and not print (because I can print from the editor)
> I'm ok with the "Send to" section (but which I never use)
> I'm ok with the "cut & copy" section too
> I'm ok with the "Create shortcut, deleted, and rename" section
> And I'm ok with the "Properties" section
>
> That's it.
> Is there a way to change the batch context menu to do just want I want it
> to do? (Mostly just "Run as Administrator" and not much else.

I think the answer is no -- though Paul may correct me, and I'll be
glad to learn something new.

Normally in HKCR in the Registry, you would find .bat, see what its
file type is, find that file type, and make our changes.

But .bat's "file type" is "PersistentHandler", and that's shared with
quite a few three-letter extensions. However, I couldn't find a
"PersistentHandler" subkey under HKCR. So those right-click menu
items may be hard-coded in Windows, or at least coded in a way that
we're not able to change.

--
Stan Brown, Tehachapi, California, USA https://BrownMath.com/
Shikata ga nai...

R.Wieser

unread,
Jul 3, 2022, 12:50:13 PM7/3/22
to
Stan,

> But .bat's "file type" is "PersistentHandler",

Not quite. AFAIK that *key*s (default) value
("{5e941d80-bf96-11cd-b579-08002b30bfeb}") is to let windows search know it
is allowed to look at the files contents (google for it).

Personally I would suggest to export (save) both the ".bat" as well as the
"batfile" (the ".bat" keys default entry) and experiment a bit.

For starters deleting keys under "batfile" -> "shell" (perhaps not the
"open" one ...) as well as the whole "ShellEx" key and see how the context
menu changes. Some stuff will disappear, but likely not everything.

If the result is acceptable some of the origional "shell" keys could be
restored (checking the context menu every time ofcourse).

Regards,
Rudy Wieser


Zaidy036

unread,
Jul 3, 2022, 3:33:31 PM7/3/22
to
On 7/3/2022 10:40 AM, John Robertson wrote:
> Is there a way to change the right click context menu for Windows *.bat
> batch files to limit the options to just those that I want there?
>
> I don't want open or open with.
> I don't want print (as I can print from the editor)
> I don't want Scan with Microsoft Defender...
> I don't want share
> I don't want Restore previous versions
> I don't want send to
>
> All I do want is what I do with a batch file.
> For example, I definitely want the "Run as administrator" item
> And I only need "Edit" and not print (because I can print from the editor)
> I'm ok with the "Send to" section (but which I never use)
> I'm ok with the "cut & copy" section too
> I'm ok with the "Create shortcut, deleted, and rename" section
> And I'm ok with the "Properties" section
>
> That's it.
> Is there a way to change the batch context menu to do just want I want it
> to do? (Mostly just "Run as Administrator" and not much else.
>
Place a "Batch Cmds" folder in context menu and add commands you want in
the folder.

Rene Lamontagne

unread,
Jul 3, 2022, 3:46:30 PM7/3/22
to
Lots off easy choices here.

https://www.thewindowsclub.com/remove-click-context-menu-items-editors

I have used a couple, no problem.

Rene

mechanic

unread,
Jul 3, 2022, 4:56:33 PM7/3/22
to
On Sun, 3 Jul 2022 08:40:49 -0600, John Robertson wrote:

> Is there a way to change the batch context menu to do just want I
> want it to do? (Mostly just "Run as Administrator" and not much
> else.

A simple search on 'howto edit the windows context menu' seems to
provide some useful suggestions.

JJ

unread,
Jul 3, 2022, 6:41:59 PM7/3/22
to
On Sun, 3 Jul 2022 08:40:49 -0600, John Robertson wrote:
> Is there a way to change the right click context menu for Windows *.bat
> batch files to limit the options to just those that I want there?
>
> I don't want open or open with.
> I don't want print (as I can print from the editor)
> I don't want Scan with Microsoft Defender...
> I don't want share
> I don't want Restore previous versions
> I don't want send to
>
> All I do want is what I do with a batch file.
> For example, I definitely want the "Run as administrator" item
> And I only need "Edit" and not print (because I can print from the editor)
> I'm ok with the "Send to" section (but which I never use)
> I'm ok with the "cut & copy" section too
> I'm ok with the "Create shortcut, deleted, and rename" section
> And I'm ok with the "Properties" section
>
> That's it.
> Is there a way to change the batch context menu to do just want I want it
> to do? (Mostly just "Run as Administrator" and not much else.

Yes, but you need to know that, all menu items are registered based on the
file type, and those menu items are registered for a pseudo file type which
represent all file types. Kind of like global menu items.

To remove e.g. the Send To menu from bat file type, it has to be
unregistered from the pseudo all-file-type, AND in order for it to be shown
for all other file types, it has to be manually registered for EACH and
every file type, including the pseudo file type which represent unknown file
types. Meaning that if there are 200 known/registered file types in the
system, the menu will need to be added onto the other 199 file types. Also,
for EACH newly registered file type, the menu will need to be manually
added.

In short, yes. It's possible, but it would be a tedious task without the
help of an automation script or program, and it will require additional
effort to re-add the no-longer-global menu items for each new file type
added into the system.

Zaidy036

unread,
Jul 3, 2022, 8:42:37 PM7/3/22
to
One way to always run as Admin would be to start the batch with:

If %1=a goto xxxx
SCHTASKS /RUN /TN <TASKNAME> at highest privileges and add argument a.
:xxxx

John Robertson

unread,
Jul 3, 2022, 10:56:27 PM7/3/22
to
On 2022/07/03 7:42 pm, Zaidy036 wrote:


> One way to always run as Admin would be to start the batch with:
>
> If %1=a goto xxxx
> SCHTASKS /RUN /TN <TASKNAME> at highest privileges and add argument a.
> :xxxx

If I can get this to work that will be beautiful as then I won't NEED that
damn context menu to run each of a hundred different batch files as admin!

Currently I select all hundred (after editing the registry to allow that),
and then, I right click once to "run as admin" and then I hit the "YES"
button time and again until all are done.

If I could put inside each batch file one line like that which didn't need
me to ALSO create a scheduled task of elevated privileges, that would be
great.

Does your method above REQUIRE a scheduled task for EACH of the hundred
batch files or can I just put that one line in each of the hundred batch
files?

Herbert Kleebauer

unread,
Jul 4, 2022, 2:22:21 AM7/4/22
to
On 04.07.2022 04:56, John Robertson wrote:
> On 2022/07/03 7:42 pm, Zaidy036 wrote:
>
>
>> One way to always run as Admin would be to start the batch with:
>>
>> If %1=a goto xxxx
>> SCHTASKS /RUN /TN <TASKNAME> at highest privileges and add argument a.
>> :xxxx
>
> If I can get this to work that will be beautiful as then I won't NEED that
> damn context menu to run each of a hundred different batch files as admin!

Create a link to the batch file, then in the properties of
the link you can specify that it should be run as administrator.

John Robertson

unread,
Jul 4, 2022, 10:37:58 AM7/4/22
to
On 2022/07/04 7:22 am, Herbert Kleebauer wrote:


>>> One way to always run as Admin would be to start the batch with:
>>>
>>> If %1=a goto xxxx
>>> SCHTASKS /RUN /TN <TASKNAME> at highest privileges and add argument a.
>>> :xxxx
>>
>> If I can get this to work that will be beautiful as then I won't NEED that
>> damn context menu to run each of a hundred different batch files as admin!
>
> Create a link to the batch file, then in the properties of
> the link you can specify that it should be run as administrator.

Thanks for the advice as I always knew that it was a difficult problem set.
Otherwise I'd already have found a solution in my Internet searches.
Search: How to run a batch file as administrator?

Creating links all day every day fifty times a day might be more work than
just selecting a dozen files at a time and right clicking "Run as Admin."

Mainly I was just trying to clean up the right click context menu so that I
can more easily see "Run as Admin" (for example, if I could put it at the
top or bottom of the list, that would make it easier, as I'm always doing
this all day every day ten times a day.

The batch files change all the time because they are configuration files
that have to be run as administrator because they need to change the
routing table to run VPN.

Each batch file has a different setting for configfile, the problem
being that confifile changes every day a few times a day, otherwise a
single batch file would have worked.

This is the basic boilerplate format of the batch file.
The openvpn config file name changes constantly.
The rest of the boilerplate stays the same.

REM Filename=20220701_1113am_172.178.9.24_udp_1515.bat
REM Must be run as administrator to change the routing table
set DIR=C:\Windows\Temp\openvpn\config\
set CMD=C:\Program Files\OpenVPN\bin\openvpn.exe
set VPN=20220701_1113am_172.178.9.24_udp_1515.ovpn
cd %DIR%
%CMD% %DIR%%VPN%

If I could add lines that put that simple batch skeleton into Administrator
mode when it's doubleclicked, that would solve the problem instantly.

I wouldn't need any rightclick context menu then.
I'd just doubleclick on the batch files.

Otherwise I select a few dozen of these *.bat files and right click and
then select "Run as Administrator" from the *.bat context menu, and then I
hit "Yes" over and over in the UAC prompts until one of those batch files
works.

When that one batch file works, I'm on VPN and then I hit "No" just once to
the UAC prompt and I'm done with interactions until I exit VPN.

Herbert Kleebauer

unread,
Jul 4, 2022, 12:06:40 PM7/4/22
to
On 04.07.2022 16:38, John Robertson wrote:

>
> Otherwise I select a few dozen of these *.bat files and right click and
> then select "Run as Administrator" from the *.bat context menu, and then I
> hit "Yes" over and over in the UAC prompts until one of those batch files
> works.
>
> When that one batch file works, I'm on VPN and then I hit "No" just once to
> the UAC prompt and I'm done with interactions until I exit VPN.

I'm not sure if I understand your problem correctly:
You have a directory with many batch files and you want
to execute them all with admin rights?

Create a file "run_them_all.cmd" with this single line (untested):

for %%i in (*.bat) call %%i


and then execute "run_them_all.cmd" as administrator.


Zaidy036

unread,
Jul 4, 2022, 12:33:16 PM7/4/22
to
On 7/3/2022 10:56 PM, John Robertson wrote:
> On 2022/07/03 7:42 pm, Zaidy036 wrote:
>
>
>> One way to always run as Admin would be to start the batch with:
>>
>> If %1=a goto xxxx
>> SCHTASKS /RUN /TN <TASKNAME>   at highest privileges and add argument a.
>> :xxxx
>
> If I can get this to work that will be beautiful as then I won't NEED
> that damn context menu to run each of a hundred different batch files as
> admin!
>
> Currently I select all hundred (after editing the registry to allow
> that), and then, I right click once to "run as admin" and then I hit the
> "YES" button time and again until all are done.
>
> If I could put inside each batch file one line like that which didn't
> need me to ALSO create a scheduled task of elevated privileges, that
> would be great.
>
> Does your method above REQUIRE a scheduled task for EACH of the hundred
> batch files or can I just put that one line in each of the hundred batch
> files?
>
Not sure if it will work but maybe set a variable instead of a fixed
TASKNAME. Also may need to kill bat before SCHTASKS

have not tried but maybe something like:

New Batch: _RunAdmin.bat:
TIMEOUT /t 1 > NUL
%_BN% a

Start of Batch to RUN:
If %1=a goto xxxx
SETx _BN <current batch name>
SCHTASKS /RUN /TN _RunAdmin
exit
:xxxx

Zaidy036

unread,
Jul 4, 2022, 12:50:07 PM7/4/22
to

Zaidy036

unread,
Jul 6, 2022, 9:12:43 PM7/6/22
to

Kerr-Mudd, John

unread,
Jul 7, 2022, 6:12:14 AM7/7/22
to
It's *removing* (most of) the context menu is what the OP wants.

--
Bah, and indeed Humbug.

Stan Brown

unread,
Jul 7, 2022, 5:26:29 PM7/7/22
to

John Robertson

unread,
Jul 7, 2022, 9:41:14 PM7/7/22
to
On 2022/07/07 10:26 pm, Stan Brown wrote:


>>> How to add to context menu:
>>> <https://www.howtogeek.com/howto/windows-vista/add-any-application-to-the-desktop-right-click-menu-in-vista/>
>>
>> It's *removing* (most of) the context menu is what the OP wants.
>
> <https://preview.tinyurl.com/4fr57rt9>
>
> which resolves to
>
> <https://www.howtogeek.com/howto/windows-vista/how-to-clean-up-your-
> messy-windows-context-menu/>

Thanks for those suggestions as doing what they said got me going finally
because I was like a cat frozen while staring at a car bearing down on it.

I started with what they called "the hard way" and then opted for "the easy
way" which was to download the nirsoft utilities.

The first step was to remove the sendto context entries.
HKEY_CLASSES_ROOT\AllFilesystemObjects\shellex\ContextMenuHandlers\Send To
https://www.howtogeek.com/howto/windows-vista/disable-the-send-to-folder-on-the-windows-explorer-context-menu/

The second step was to remove the openwith context entries
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
I removed entries in the .bat registry key OpenWithList registry subkey.
https://www.howtogeek.com/howto/18119/remove-programs-from-open-with-menu-in-explorer/

The third step was to use ShellExView, which handles shellex items.
https://www.nirsoft.net/utils/shexview.html
I searched for .bat" which only had three lines all of which I disabled.
edit
Run as different user
runas

But I had to re-enable "runas" to "Run as Administrator" which is the only
context menu I need for a batch file.

The fourth step was to use ShellMenuView, which handles regular shell items
I removed the .openWith but I couldn't see how to get rid of the "Open" and
"Print" neither of which I'll ever need for a batch file.
https://www.nirsoft.net/utils/shell_menu_view.html

Then I went back to the hard way because at first I also couldn't get rid
of "Share" or "Scan with Microsoft Defender" or "Scan with Malwarebytes" or
"Restore previous version" or "Open" or "Print" context menu entries.

Then I found this which said to go to Settings : General : Windows Explorer
settings in malware bytes and turn it off but it was already off.
So I deleted malwarebytes instead which cleaned up that menu entry.
https://windowsloop.com/remove-scan-with-malwarebytes-in-right-click-menu/

To remove the scan with microsoft defender context menu I ran this file
https://www.tenforums.com/attachments/tutorials/286913d1594060844-add-remove-scan-microsoft-defender-context-menu-windows-10-a-remove_scan_with_microsoft_defender_context_menu.reg
https://www.tenforums.com/tutorials/18145-add-remove-scan-microsoft-defender-context-menu-windows-10-a.html
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\EPP]
[-HKEY_CLASSES_ROOT\CLSID\{09A47860-11B0-4DA5-AFA5-26D86198A780}]
[-HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers\EPP]
[-HKEY_CLASSES_ROOT\Drive\shellex\ContextMenuHandlers\EPP]

To remove the "Share" item from the context menu I went to
Computer\HKEY_CLASSES_ROOT\*\shellex\ContextMenuHandlers\ModernSharing
https://www.thewindowsclub.com/remove-share-button-context-menu-windows-10#

To remove "Restore previous versions" from the context menu I went to
https://www.tenforums.com/tutorials/79513-remove-previous-versions-context-menu-properties-windows-10-a.html
https://www.tenforums.com/attachments/tutorials/125429d1489709794-remove-previous-versions-context-menu-properties-windows-10-a-remove_previous_versions_from_properties_and_context_menu.reg

To remove the "Print" from the context menu I went to
https://winaero.com/remove-print-context-menu-in-windows-10/
https://winaero.com/download.php?view.2309

At this point I realized what someone was trying to warn me about which is
that it wasn't just affecting "batch" files but most other files, so I
didn't remove the "Open" but at least now the "Run as administrator" is the
second item down (after "Open") and I'm down to about ten entries in total.

Much surprised nothing required a reboot.
Thanks for all the help.
I'm sure I'll be sorry in days to come if other file types are affected.
Such is editing the registry (I didn't bother with a backup).

Heron

unread,
Jul 8, 2022, 12:50:03 PM7/8/22
to

Bugsy

unread,
Jul 8, 2022, 1:05:56 PM7/8/22
to
John Robertson <sp...@flippers.com> wrote:

> At this point I realized what someone was trying to warn me about which is
> that it wasn't just affecting "batch" files but most other files, so I
> didn't remove the "Open" but at least now the "Run as administrator" is the
> second item down (after "Open") and I'm down to about ten entries in total.

There might be a way to flip them but I don't know if this will do it.
https://www.techspot.com/downloads/7095-easy-context-menu.html
https://www.techspot.com/downloads/downloadnow/7095/?evp=82838668d77594315e27a94ae8cf8659&file=9318
https://files02.tchspt.com/temp/EcMenu_x64.exe
--
Please wear your mask!
Bugs are everywhere. :)
!__!
(@)(@)
\.'||'./
-: :: :-
/'..''..'\

Paul

unread,
Jul 8, 2022, 3:03:40 PM7/8/22
to
0 new messages