diff --git a/elan-init.ps1 b/elan-init.ps1 index b6a9560..5088e3e 100644 --- a/elan-init.ps1 +++ b/elan-init.ps1 @@ -37,8 +37,23 @@ param( # There are no Windows ARM releases yet, use emulated x64 $_arch = "x86_64-pc-windows-msvc" $_ext = ".exe" -$temp = [System.IO.Path]::GetTempPath() + +if ($ExecutionContext.SessionState.LanguageMode -eq 'FullLanguage') { + $temp = [System.IO.Path]::GetTempPath() +} +else +{ + # CLM-safe temp path: [System.IO.Path]::GetTempPath() is a static method call on a non-allow-listed type and is blocked in ConstrainedLanguage. + # Use the environment variable instead (reading $env: is permitted in CLM) to mirror the lookup behaviour of [System.IO.Path]::GetTempPath() + $temp = $env:TMP + if (-not $temp) { $temp = $env:TEMP } + if (-not $temp) { $temp = $env:USERPROFILE } + if (-not $temp) { $temp = $env:SystemRoot } + if (-not $temp) { throw "Unable to resolve a temporary directory. All candidate sources (TMP/TEMP/USERPROFILE/SystemRoot) were not found." } +} + $_dir = Join-Path $temp "elan" + if (-not (Test-Path -Path $_dir)) { $null = New-Item -ItemType Directory -Path $_dir }