Associate .docx with swriter.exe LibreOffice (with PowerShell)

Abstract: Fixes Windows file association for .docx files to launch LibreOffice Writer by correctly configuring the HKEY_CLASSES_ROOT registry via PowerShell.

Created: 2026-09-21 by

Use PowerShell to modify the Windows Registry under HKEY_CLASSES_ROOT to associate .docx files with LibreOffice Writer. This approach correctly registers the file handler without relying on deprecated methods or incorrect hive locations, ensuring that double-clicking a document launches the correct application immediately.

Why Standard Methods Fail

Many users attempt to fix file associations by modifying the Current User hive (HKEY_CURRENT_USER) or by using legacy tools that rely on sending keystrokes to refresh the shell. These methods are often ineffective because modern Windows versions enforce strict registry structures for default programs. The association of file types is primarily managed through the HKEY_CLASSES_ROOT (HKCR) hive, which aggregates keys from both the machine and user hives but serves as the authoritative source for the shell.

Attempting to set the AppUserModelId in the wrong location does not change which executable opens the file. It only affects how the application appears in the taskbar or notification center once it is already running. Therefore, correcting the registry path is the only reliable way to ensure that the operating system routes the file opening request to soffice.exe or swriter.exe.

Preparing the PowerShell Script

To automate this process, you need a script that writes specific values to the registry. You should run PowerShell as an administrator to ensure you have the necessary permissions to write to HKEY_CLASSES_ROOT. While some operations can be performed per-user, system-wide changes require elevated privileges. The script below targets the .docx extension and links it to the LibreOffice Writer application.

Before running any registry modification script, it is prudent to back up your current settings. You can export the relevant keys using the regedit tool or by exporting the specific paths via PowerShell. This ensures you can revert changes if something goes wrong. Additionally, verify the exact path to your LibreOffice installation, as it may vary depending on whether you installed the 32-bit or 64-bit version, and where you chose to install it.

The Correct Registry Structure

The core of the solution lies in creating or updating two main registry keys. First, you must define the ProgID for the file type. Second, you must link the file extension to that ProgID. The following structure outlines the necessary entries:

  • Extension Key: Located at HKEY_CLASSES_ROOT\.docx. The default value should be set to a unique identifier, such as LibreOffice.Document.12.
  • ProgID Key: Located at HKEY_CLASSES_ROOT\LibreOffice.Document.12. This key contains the details about the file type, including the friendly name.
  • Shell Open Command: Located at HKEY_CLASSES_ROOT\LibreOffice.Document.12\shell\open\command. This is the most critical part. The default value here must contain the full path to the executable followed by the argument placeholder for the file path.

It is important to note that swriter.exe is often a wrapper or specific component. In many installations, calling soffice.exe with the --writer flag is more robust. However, if your goal is specifically to use swriter.exe, ensure that the path points directly to that binary. The command line argument must include "%1" to pass the filename of the opened document to the application.

Executing the PowerShell Commands

You can implement these changes using the New-ItemProperty cmdlet. Below is a concise example of how to set the association. Replace the path C:\Program Files\LibreOffice\program\swriter.exe with your actual installation path.

# Define the file extension and ProgID
$ext = ".docx"
$progId = "LibreOffice.Document.12"
$exePath = '"C:\Program Files\LibreOffice\program\swriter.exe"'

# Set the extension to the ProgID
Set-ItemProperty -Path "HKCU:\Software\Classes\$ext" -Name "(Default)" -Value $progId

# Create the ProgID structure if it doesn't exist
New-Item -Path "HKCU:\Software\Classes\$progId" -Force | Out-Null
Set-ItemProperty -Path "HKCU:\Software\Classes\$progId" -Name "(Default)" -Value "LibreOffice Writer Document"

# Set the open command
New-Item -Path "HKCU:\Software\Classes\$progId\shell\open\command" -Force | Out-Null
Set-ItemProperty -Path "HKCU:\Software\Classes\$progId\shell\open\command" -Name "(Default)" -Value "$exePath `"%1`""

This script modifies the Current User hive under Software\Classes, which is merged into HKEY_CLASSES_ROOT for the user. This is often sufficient for personal use and avoids the need for administrative privileges in some contexts. However, for system-wide changes, you would target HKEY_LOCAL_MACHINE\SOFTWARE\Classes instead. After running the script, you may need to restart Explorer or log off and back on for the changes to take effect fully.

Verifying the Association

Once the script has executed, verify that the association is correct. Right-click any .docx file and select Properties. Under the "Opens with" section, it should now display LibreOffice Writer. If it still shows Microsoft Word, check the registry entries to ensure there are no conflicting keys higher in the hierarchy. You can also test the association by double-clicking a file; it should launch LibreOffice Writer with the document loaded.

If you encounter issues, consider checking the event viewer for errors related to file handlers. Sometimes, third-party software can override these settings. For more information on handling file formats and time stamps within office documents, you might find Understanding the 14-Digit Time Format useful for debugging metadata issues that sometimes accompany file association problems.

Frequently Asked Questions

Do I need to run PowerShell as Administrator?

If you modify the HKCU hive under Software\Classes, administrative rights are usually not required. However, if you want to change the association for all users on the computer, you must run PowerShell as Administrator and modify the HKLM hive. Always ensure you have the correct permissions before attempting to write to registry keys.

Why did my previous script fail to update the icon?

File associations and icons are stored in different registry locations. While the command path sets the executable, the icon is defined in the DefaultIcon subkey under your ProgID. You must separately create or update HKEY_CLASSES_ROOT\LibreOffice.Document.12\DefaultIcon to point to the LibreOffice executable or its icon resource file.

Can I use soffice.exe instead of swriter.exe?

Yes, using soffice.exe with the --writer parameter is often recommended because it is the main launcher for LibreOffice. It handles various arguments more consistently than swriter.exe. Simply replace the executable path in the registry command with "C:\Path\To\soffice.exe" --writer "%1".

What happens if I delete the association?

If you delete the registry keys associated with .docx, Windows will likely revert to using Microsoft Word if it is installed, or prompt you to choose an app when you try to open a file. Deleting the keys is a safe way to reset the association to its default state without reinstalling any software.

How do I handle spaces in the installation path?

Always wrap the executable path in quotes within the registry value. In PowerShell, you can achieve this by enclosing the entire command string in double quotes and escaping the inner quotes for the file argument. This ensures that Windows Explorer passes the file path correctly even if it contains spaces.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More