Skip to content

Commit 8c21fb8

Browse files
committed
cleanup: remove admin elevation code (will work with or without elevated privileges)
1 parent 0fb3ec7 commit 8c21fb8

3 files changed

Lines changed: 163 additions & 6 deletions

File tree

‎package-lock.json‎

Lines changed: 129 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"dependencies": {
2121
"electron-updater": "^6.1.0",
22+
"is-admin": "^4.0.0",
2223
"lucide-react": "^0.263.1",
2324
"react": "^18.3.0",
2425
"react-dom": "^18.3.0",

‎src/main/admin.ts‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { app, dialog } from 'electron'
2+
import { execFile } from 'child_process'
3+
import isAdmin from 'is-admin'
4+
5+
export async function ensureAdmin(): Promise<boolean> {
6+
const admin = await isAdmin()
7+
8+
if (!admin) {
9+
const { response } = await dialog.showMessageBox({
10+
type: 'warning',
11+
title: 'Administrator Rights Required',
12+
message: 'DiskOH needs administrator privileges to scan your drives.',
13+
detail: 'Click "Yes" to restart the application with admin rights.',
14+
buttons: ['Yes', 'Cancel'],
15+
defaultId: 0,
16+
})
17+
18+
if (response === 0) {
19+
execFile('powershell.exe', [
20+
'-NoProfile',
21+
'-Command',
22+
`Start-Process -FilePath "${app.getPath('exe')}" -Verb RunAs`,
23+
])
24+
app.quit()
25+
return false
26+
} else {
27+
app.quit()
28+
return false
29+
}
30+
}
31+
32+
return true
33+
}

0 commit comments

Comments
 (0)