When right-clicked, batch files (.BAT) don’t offer the Open with handler in the context menu by default. This helps prevent unauthorized editing of its content through alternative applications like code editors, which can lead to accidental misconfigurations. In this guide, you’ll learn how to add or remove the Open with .BAT File context menu option.
Managing ‘Open with’ in the context menu of BAT files
Administrators can add or remove the Open with context menu option for BAT files, helping control who manages them. When disabled, this removes the option, locking BAT file editing privileges using code editors.
However, adding the option to your context menu can help ease the editing and troubleshooting process of BAT files. That said, it’s important to manage this in environments where prioritizing script integrity or editing flexibility is crucial.
📌 Prerequisites:
- Any Windows 11 PC
- Administrative privileges
- Access to Windows administrator tools (Registry, CMD, PowerShell, and GPO)
📌 Recommended deployment strategies:
Method 1: Managing BAT file context menu options via Registry association
The Registry defines how Windows interacts with BAT files when given a specific command. By changing how the Registry defines the context menu for BAT files, administrators can hide or add the option for end users.
⚠️ Warning: The HKCR Registry hive dictates how Windows interacts with BAT files. Misconfiguring this hive can break file associations, preventing users from running and interacting with files in their system. (See ⚠️ Things to look out for.)
📌 Use Case: Leverage the Registry to add or remove the Open with option for BAT files system-wide.
📌 Prerequisite: Windows Registry backup.
Steps:
- Press Win + R, type regedit in the dialog box, then press Ctrl + Shift + Enter.
- Navigate the following path: HKEY_CLASSES_ROOT\batfile\shellex\ContextMenuHandlers\
- Do the step that reflects the change you want in the BAT file context menu.
- To add the Open with option for BAT file context menus:
- Right-click ContextMenuHandlers, then select New > Key.
- Name the key OpenWith.
- Right-click ContextMenuHandlers, then select New > Key.
- To remove the Open with option for BAT file context menus:
- Right-click the OpenWith subkey, then select Delete.
- Confirm the subsequent prompt to confirm the change.
- To add the Open with option for BAT file context menus:
- Close the Registry, right-click on the desktop, and select Refresh to apply the change.
- Alternatively, you can restart File Explorer instead.
Method 2: Automating the Registry change using Command Prompt
Manually editing the Registry can lead to misconfigurations, becoming more error-prone as you implement it for multiple devices. As a workaround, you can automate this process using the Command Prompt.
⚠️ Important: Double-check syntax and formatting consistency before executing scripts and commands to avoid misconfigurations. (See ⚠️ Things to look out for.)
📌 Use Cases: Use commands in CMD to automate the management of the Open with context menu option for BAT files. Additionally, you can convert the command below to a BAT file for faster and repeated deployments.
📌 Prerequisite:
- Windows Registry backup
- Elevated Command Prompt access
💡 Tip: Understanding how to use Command Prompt helps ensure smoother execution.
Steps:
- Press Win + R, type cmd, then press Ctrl + Shift + Enter.
- Execute the command that suits your target configuration:
- To add Open with in the BAT file context menu:
reg add “HKCR\batfile\shellex\ContextMenuHandlers\OpenWith” - To remove Open with in the BAT file context menu:
reg delete “HKCR\batfile\shellex\ContextMenuHandlers\OpenWith” /f
- To add Open with in the BAT file context menu:
- Close CMD, then refresh the desktop or restart the Windows Explorer app.
Method 3: Add or remove the ‘Open with’ option for BAT files via PowerShell
While PowerShell and CMD automate Registry configurations, the former offers remote deployment and seamless integration with modern deployment tools.
📌 Use Cases: Use PowerShell scripts to automate manual Registry configurations. Administrators can also use PowerShell to remotely deploy scripts for domain-joined and non-domain endpoints using remote PowerShell tools.
📌 Prerequisites:
- Windows Registry backup
- Elevated PowerShell prompt access
💡 Tip: You can refer to this PowerShell command cheat sheet to know more about the outlined scripts below.
Steps:
- Press Win + R to open Run, type PowerShell, and press Ctrl + Shift + Enter.
- Execute the script that reflects the BAT file content menu change you want.
- Enter the following to remove the Open with option:
Remove-Item -Path “Registry::HKEY_CLASSES_ROOT\batfile\shellex\ContextMenuHandlers\OpenWith” -Force - Enter the following to add the Open with option:
New-Item -Path “Registry::HKEY_CLASSES_ROOT\batfile\shellex\ContextMenuHandlers” -Name “OpenWith” -Force | Out-Null
- Enter the following to remove the Open with option:
- Restart File Explorer or press refresh on the desktop to apply the change.
Method 4: Deploy Open with option configurations for BAT files via GPP
The Group Policy Management Console allows administrators to push Group Policy Preferences across an environment, ensuring setting consistency at scale.
⚠️ Important: Test configurations on a local machine within a controlled environment before deploying. (See ⚠️ Things to look out for.)
📌 Use Cases: Use Group Policy Preferences to set a default BAT file context menu configuration for all end users in an environment. Additionally, deploying a GPP helps eliminate the manual application of scripts, as this method configures all target devices simultaneously.
📌 Prerequisites:
- Group Policy Management Console (gpmc.msc) access
- Domain admin privileges
Steps:
- Press Win + R, type gpmc.msc, and press Enter.
- Right-click the target domain or Organizational Unit (OU), then select Create a GPO in this domain, and Link it here….
- Right-click the newly created GPO and select Edit.
- Navigate the following path: Computer Configuration > Preferences > Windows Settings > Registry
- Right-click the Registry node, choose New > Registry item, and configure it to reflect your desired change:
- Follow this configuration to add the Open with option.
Settings Value Action Update Hive HKEY_CLASSES_ROOT Key Path batfile\shellex\ContextMenuHandlers\OpenWith Value Name – Value type – Value data – - Follow this configuration to remove the Open with option.
Settings Value Action Delete Hive HKEY_CLASSES_ROOT /Key Path batfile\shellex\ContextMenuHandlers\OpenWith Value Name – Value type – Value data –
- Follow this configuration to add the Open with option.
- Close GPMC and wait for the automatic Policy refresh to apply the change.
- Optionally, you can go to a client machine and enter the following on a PowerShell prompt: gpupdate /force
💡 Note: Group Policy Preferences apply settings that end users can change unless hardening is applied.
⚠️ Things to look out for
Risks | Potential Consequences | Reversals |
Manually editing the HKEY_CLASSES_ROOT key (HKCR) | Misconfiguring the HKCR can break file associations, causing apps to malfunction, poor system stability, or boot issues. | We recommend backing up your Windows Registry before making changes to ensure quick rollback in case of misconfigurations. |
Syntax and formatting inaccuracies when working with scripts and commands | Inaccurate scripts can lead to failed configurations or unintended misconfigurations that can negatively affect the system. | Double-check script syntax, accuracy, and formatting before executing to prevent misconfigurations. Alternatively, copy the ready-to-run scripts outlined in this guide for safer script execution. |
Deploying untested and unverified configurations across an environment | Without proper testing, deployed configurations may harbor hidden errors and misconfigurations that can degrade system performance or cause unexpected behavior. | Always test configurations within controlled local environments before deploying across an organization to ensure they work as intended. |
Not logged in as an administrator when making the configuration | BAT file associations are managed system-wide and require admin privileges for successful configurations. | Ensure that you have the proper elevation before proceeding. To check this, open a PowerShell prompt and enter the following: [bool]([Security.Principal.WindowsPrincipal] If the result shows TRUE, you’re logged in as an admin. |
Considerations when managing BAT file context menu handlers
In this section, we’ll look into key considerations related to deployment methods, file execution behavior, and rollback options. Understanding the broader impact of this configuration helps ensure consistent and successful integration of BAT file changes across an environment.
No official ADMX policy for handling BAT file context menu handlers
No official ADMX policy directly handles the configuration of BAT file context menu handlers. The recommended way to do this is to add or remove the OpenWith subkey within the Registry. You can use PowerShell and CMD scripts to automate this process, or deploy it at scale via Group Policy.
Effects on file execution
Managing the OpenWith key only affects the visibility of the Open with option inside the context menu of BAT files. Whether the option is added or removed, users can still execute BAT files by double-clicking them.
Rollback methods
Toggling the Open with option for BAT files only involves creating or deleting the OpenWith subkey in the Registry. However, Registry changes are error-prone, and even non-destructive changes call for a backup in case of accidental deletions and misconfigurations.
Remove ‘Open with’ from the context menu to maintain BAT file integrity
Administrators can show or hide the Open with option for BAT files to control the editing capability of end users. Removing this handler within the context menu prevents unauthorized script edits, maintaining the file’s integrity.
Configuring the registry is recommended to manage BAT file context menu handlers system-wide. To minimize errors, you can leverage CMD or PowerShell scripts to automate the process consistently, especially for non-domain deployments. For administrators managing domain-joined environments, you can configure the Registry across all endpoints by deploying Group Policy Preferences.
Related topic:
- What is BAT file (.BAT)?
- How to Add “Take Ownership” to the Context Menu in Windows
- How to Add “Find Empty Folders” to the Context Menu in Windows 11
- How to Add or Remove “Open in Windows Terminal” Expandable Context Menu in Windows 10
- How to Add Copy Path to Context Menu in Windows 10
- How to Add or Remove ‘Install CAB’ Context Menu in Windows 10