Closed writingdeveloper closed 3 years ago
You can either run the Node process from an elevated shell or use Start-Process
with flags to open an elevated PowerShell and run your script from it. There's a working example of how to do this here. I'm not sure if that example will work for your script in particular but I've had success triggering elevated prompts for a lot of things.
Just a head's up the main issue I've run into with this is that it gets hairy really fast translating strings from JS into strings that PowerShell understands because the syntax for escape characters in PS is bonkers.
@Jack-Barry Re: the heads up issue: Couldn't you between JSON to make that easier?
I'm developing 'Windows Local User Management App' with Node.js and Express.js.
When I search to do this, it has two methods.
First, Using 'node-powershell' package in npm. Second, Using 'child_process' built-in to Node.js.
I thought 'node-powershell' package has some examples on google. So I think it is easy, but It's seems that it's not working, and also there are no error messages either!
This is the working script in Windows PowerShell.
So I put this code into Node.js code. But it's not working. The reason why I put the
[System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8
code, is When I put Korean characters it brokes.This is the code uses node-powershell package.
And it should be run as Administrator but I set powershell, always run as Administrator.