Title: Enabling Non-Administrator Access to ChkDsk for Electron Apps (Windows 10/11)
Introduction
In this article, we will discuss how to enable non-administrator access to the ChkDsk tool for Electron applications on Windows 10/11. This is particularly useful when deploying an Electron application, as it helps resolve potential issues that may arise due to file system permissions.
Prerequisites
Before we begin, ensure that you have the following:
- Windows 10/11 operating system
- An Electron application
- Node.js and npm installed
- Electron package installed
Steps to Enable Non-Admin Access to ChkDsk
-
Open the command prompt as an administrator.
-
Navigate to the directory where your Electron application is located.
-
Register the ChkDsk command for non-admin users using the following command:
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /fThis command adds the necessary registry key to allow non-admin users to run ChkDsk.
-
Create a batch file named
chkdsk.batin the same directory as your Electron application. Open the file using a text editor and paste the following code:@echo off setlocal set "drive=%1" if "%drive%" == "" ( echo Usage: chkdsk.bat [drive:] goto end ) if not "%drive:~0,1%" == ":" ( echo Invalid drive letter. goto end ) if exist "%drive%\chkdsk.exe" ( echo Chkdsk.exe exists on the specified drive. goto end ) if exist "%SystemRoot%\System32\chkdsk.exe" ( start /wait "%SystemRoot%\System32\chkdsk.exe" %drive% /f /x goto end ) echo Chkdsk.exe not found. :end endlocalThis batch file will call the ChkDsk tool and pass the specified drive as an argument.
-
Update the
package.jsonfile of your Electron application to include a new script that runs the batch file:"scripts": { "start": "electron .", "chkdsk": "start chkdsk.bat %1" }Replace
%1with the drive letter you want to check (e.g.,C:). -
Now, you can run the ChkDsk tool from your Electron application using the following command:
npm run chkdsk [drive:]Replace
[drive:]with the drive letter you want to check.
Conclusion
In this article, we discussed how to enable non-administrator access to the ChkDsk tool for Electron applications on Windows 10/11. By following the steps outlined, you can ensure your application can perform disk checks without requiring administrator privileges.