From 6ccbebda27ddfa60b2e4d6d5dbe0f6e74ef1c878 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 25 Jan 2019 13:14:29 -0800 Subject: [PATCH] Improve check for developer mode by checking minimum required build number (#8749) * Improve check for developer mode by checking minimum required build number The test would fail if the developer mode is enabled but the machine has an older build than the minimum required build. The change adds a check for the build version in the test. * Update test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 --- .../namespaces/FileSystemProvider.cs | 5 +++-- .../Microsoft.PowerShell.Management/New-Item.Tests.ps1 | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index a53534d60..dcb42ecff 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -2449,8 +2449,9 @@ namespace Microsoft.PowerShell.Commands { // The new AllowUnprivilegedCreate is only available on Win10 build 14972 or newer var flags = isDirectory ? NativeMethods.SymbolicLinkFlags.Directory : NativeMethods.SymbolicLinkFlags.File; - if (Environment.OSVersion.Version.Major == 10 && Environment.OSVersion.Version.Build >= 14972 || - Environment.OSVersion.Version.Major >= 11) + + Version minBuildOfDeveloperMode = new Version(10, 0, 14972, 0); + if (Environment.OSVersion.Version >= minBuildOfDeveloperMode) { flags |= NativeMethods.SymbolicLinkFlags.AllowUnprivilegedCreate; } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 index 9eaf79239..7f49225dd 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/New-Item.Tests.ps1 @@ -262,7 +262,9 @@ Describe "New-Item with links fails for non elevated user if developer mode not $testlink = "testlink" $FullyQualifiedFile = Join-Path -Path $TestDrive -ChildPath $testfile $TestFilePath = Join-Path -Path $TestDrive -ChildPath $testlink - $developerMode = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock -ErrorAction SilentlyContinue).AllowDevelopmentWithoutDevLicense -eq 1 + $developerModeEnabled = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock -ErrorAction SilentlyContinue).AllowDevelopmentWithoutDevLicense -eq 1 + $minBuildRequired = [System.Environment]::OSVersion.Version -ge "10.0.14972" + $developerMode = $developerModeEnabled -and $minBuildRequired } AfterEach {