Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
)
if (powerShell.length === 0) {
return null
}
const first = powerShell[0]
// NOTE:
// on Windows 7 these are both REG_SZ, which technically isn't supposed
// to contain unexpanded references to environment variables. But given
// it's also %SystemRoot% and we do the expanding here I think this is
// a fine workaround to do to support the maximum number of setups.
if (
first.type === RegistryValueType.REG_EXPAND_SZ ||
first.type === RegistryValueType.REG_SZ
) {
const path = first.data.replace(
/^%SystemRoot%/i,
process.env.SystemRoot || 'C:\\Windows'
)
if (await pathExists(path)) {
return path
} else {
log.debug(
`[PowerShell] registry entry found but does not exist at '${path}'`
)
}
}