I want to create a program that can delete user accounts even if they have files locked to administrators on the pc. I have it built so normal accounts are deleted, but it errors due to missing permissions if they have locked files. Is there a way I can either elevate my script, or bypass the restriction? Here is the current code to see how everything is formatted, if that helps.
const fs = require('fs')
process.on('uncaughtException', err => {
console.log(err);
})
process.on('unhandledRejection', err => {
console.log(err);
})
async function start() {
try {
var num = 0;
for (var file of fs.readdirSync("C:/Users", () => { })) {
if (!isNaN(Number(file))) {
if (parseInt(file) <= 219999) {
fs.rmSync("C:/Users" + "/" + file, { recursive: true, force: true });
console.log("Removed User: " + file);
num += 1;
}
} else {
console.log("Skipped " + file);
}
}
console.log("\n\n" + "Removed " + num + " users!\n\nClosing window...")
setTimeout(() => {
process.kill();
},2500)
} catch (err) {
console.log(err);
console.log("\nMissing administor privileges!");
}
}
start();