Skip to content

Commit

Permalink
Merge pull request Romanitho#51 from Romanitho/fix-scope
Browse files Browse the repository at this point in the history
Fix scope machine 32 bits cmd on 64 bits system
  • Loading branch information
Romanitho authored Jun 17, 2022
2 parents 84eb306 + 0dadcf8 commit bbaa34a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions winget-install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,31 @@ function Get-WingetCmd {
function Add-ScopeMachine {
#Get Settings path for system or current user
if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) {
$SettingsPath = "$Env:windir\system32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\settings.json"
if ([Environment]::Is64BitProcess -ne [Environment]::Is64BitOperatingSystem) {
$SettingsPath = "$Env:windir\sysnative\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\settings.json"
}
else {
$SettingsPath = "$Env:windir\System32\config\systemprofile\AppData\Local\Microsoft\WinGet\Settings\settings.json"
}
}
else {
$SettingsPath = "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json"
}

#Check if setting file exist, if not create it and set
#Check if setting file exist, if not create it
if (Test-Path $SettingsPath) {
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
}

if (!$ConfigFile) {
$ConfigFile = @{}
}
if ($ConfigFile.installBehavior.preferences.scope) {
$ConfigFile.installBehavior.preferences.scope = "Machine"

if ($ConfigFile.installBehavior.preferences) {
Add-Member -InputObject $ConfigFile.installBehavior.preferences -MemberType NoteProperty -Name 'scope' -Value 'Machine' -Force
}
else {
$Scope = New-Object PSObject -Property $(@{scope = "Machine" })
$Scope = New-Object PSObject -Property $(@{scope = 'Machine' })
$Preference = New-Object PSObject -Property $(@{preferences = $Scope })
Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $Preference -Force
}
Expand Down

0 comments on commit bbaa34a

Please sign in to comment.