Skip to content

Commit

Permalink
powerShell added default path
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhildebrandt committed Jan 3, 2025
1 parent 392473e commit aff943c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const _sunos = (_platform === 'sunos');

if (_windows) {
util.getCodepage();
util.getPowershell();
}

// ----------------------------------------------------------------------------------
Expand Down
16 changes: 14 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let _psChild;
let _psResult = '';
let _psCmds = [];
let _psPersistent = false;
let _powerShell = '';
const _psToUTF8 = '$OutputEncoding = [System.Console]::OutputEncoding = [System.Console]::InputEncoding = [System.Text.Encoding]::UTF8 ; ';
const _psCmdStart = '--###START###--';
const _psError = '--ERROR--';
Expand Down Expand Up @@ -332,6 +333,16 @@ function findObjectByKey(array, key, value) {
return -1;
}

function getPowershell() {
_powerShell = 'powershell.exe';
if (_windows) {
defaultPath = `${WINDIR}\\WindowsPowerShell\\v1.0\\powershell.exe`;
if (fs.existsSync(defaultPath)) {
_powerShell = defaultPath;
}
}
}

function getWmic() {
if (os.type() === 'Windows_NT' && !wmicPath) {
wmicPath = WINDIR + '\\system32\\wbem\\wmic.exe';
Expand Down Expand Up @@ -401,7 +412,7 @@ function powerShellProceedResults(data) {

function powerShellStart() {
if (!_psChild) {
_psChild = spawn('powershell.exe', ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-NoExit', '-Command', '-'], {
_psChild = spawn(_powerShell, ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-NoExit', '-Command', '-'], {
stdio: 'pipe',
windowsHide: true,
maxBuffer: 1024 * 20000,
Expand Down Expand Up @@ -479,7 +490,7 @@ function powerShell(cmd) {
return new Promise((resolve) => {
process.nextTick(() => {
try {
const child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], {
const child = spawn(_powerShell, ['-NoProfile', '-NoLogo', '-InputFormat', 'Text', '-NoExit', '-ExecutionPolicy', 'Unrestricted', '-Command', '-'], {
stdio: 'pipe',
windowsHide: true,
maxBuffer: 1024 * 20000,
Expand Down Expand Up @@ -2595,3 +2606,4 @@ exports.semverCompare = semverCompare;
exports.getAppleModel = getAppleModel;
exports.checkWebsite = checkWebsite;
exports.cleanString = cleanString;
exports.getPowershell = getPowershell;

0 comments on commit aff943c

Please sign in to comment.