Use execSync to execute powershell command

This commit is contained in:
Sander Declerck 2026-01-19 16:11:51 +01:00
parent a7315d29c4
commit 1de6a4ac4b
No known key found for this signature in database

View file

@ -1,6 +1,7 @@
import { arch, tmpdir } from "os"; import { arch, tmpdir } from "os";
import { unlinkSync } from "fs"; import { unlinkSync } from "fs";
import { join } from "path"; import { join } from "path";
import { execSync } from "child_process";
import { ui } from "../environment/userInteraction.js"; import { ui } from "../environment/userInteraction.js";
import { safeSpawn } from "../utils/safeSpawn.js"; import { safeSpawn } from "../utils/safeSpawn.js";
import { import {
@ -81,18 +82,15 @@ async function uninstallIfInstalled() {
const powershellScript = `$app = Get-WmiObject -Class Win32_Product -Filter "Name='SafeChain Agent'"; if ($app) { Write-Output $app.IdentifyingNumber }`; const powershellScript = `$app = Get-WmiObject -Class Win32_Product -Filter "Name='SafeChain Agent'"; if ($app) { Write-Output $app.IdentifyingNumber }`;
ui.writeVerbose(`Finding product code with PowerShell`); ui.writeVerbose(`Finding product code with PowerShell`);
const result = await safeSpawn("powershell", ["-Command", powershellScript], { let productCode;
stdio: "pipe", try {
}); productCode = execSync(`powershell -Command "${powershellScript}"`, {
encoding: "utf8",
if (result.status !== 0) { }).trim();
ui.writeVerbose( } catch {
`No existing installation found (fresh install). Output: ${result.stdout} ${result.stderr}`, ui.writeVerbose("No existing installation found (fresh install).");
);
return; return;
} }
const productCode = result.stdout.trim();
if (!productCode) { if (!productCode) {
ui.writeVerbose("No existing installation found (fresh install)."); ui.writeVerbose("No existing installation found (fresh install).");
return; return;