I'm trying to run the below code but I get the error New-NetFireWallRule : Access is denied.
let ps = new pshell({
verbose: true,
executionPolicy: "Bypass"
});
ps.addCommand(
'Remove-NetFirewallRule -DisplayName "electron.exe"'
);
ps.addCommand(
'New-NetFirewallRule -DisplayName "electron.exe" -Enabled True -Direction Inbound -LocalPort ANY -Protocol ANY -Profile Private,Public -Action Allow -Program "' +
process.execPath +
'"'
);
ps.invoke()
.then(output => {
/**
* successfully remove firewall rules, now create new rules
*/
console.log(output)
ps.dispose();
})
.catch(err => {
/**
* Failed to remove firewall rule, go ahead and create new rules anyway
*/
console.log(err);
ps.dispose();
});
});
Running the commands straight in PS works fine. So I put it down to permission problems but I'm a bit stuck on how to elevate PS using node-powershell.
I've tried addingcommand: 'Start-Process -FilePath "powershell" -Verb RunAs' when the new instance is created and it runs without error but does not delete or create the firewall rules.
I'm trying to run the below code but I get the error New-NetFireWallRule : Access is denied.
Running the commands straight in PS works fine. So I put it down to permission problems but I'm a bit stuck on how to elevate PS using node-powershell. I've tried adding
command: 'Start-Process -FilePath "powershell" -Verb RunAs'
when the new instance is created and it runs without error but does not delete or create the firewall rules.Any help would be appreciated.