File tree Expand file tree Collapse file tree
src/System.Management.Automation/namespaces
test/powershell/Modules/Microsoft.PowerShell.Management Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2434,10 +2434,14 @@ protected override void NewItem(
24342434
24352435 private static bool WinCreateSymbolicLink ( string path , string strTargetPath , bool isDirectory )
24362436 {
2437- int created = NativeMethods . CreateSymbolicLink (
2438- path ,
2439- strTargetPath ,
2440- ( isDirectory ? NativeMethods . SymbolicLinkFlags . Directory : NativeMethods . SymbolicLinkFlags . File ) | NativeMethods . SymbolicLinkFlags . AllowUnprivilegedCreate ) ;
2437+ // The new AllowUnprivilegedCreate is only available on Win10 build 14972 or newer
2438+ var flags = isDirectory ? NativeMethods . SymbolicLinkFlags . Directory : NativeMethods . SymbolicLinkFlags . File ;
2439+ if ( Environment . OSVersion . Version . Major >= 10 && Environment . OSVersion . Version . Build >= 14972 )
2440+ {
2441+ flags |= NativeMethods . SymbolicLinkFlags . AllowUnprivilegedCreate ;
2442+ }
2443+
2444+ int created = NativeMethods . CreateSymbolicLink ( path , strTargetPath , flags ) ;
24412445 return ( created == 1 ) ? true : false ;
24422446 }
24432447
Original file line number Diff line number Diff line change @@ -269,13 +269,13 @@ Describe "New-Item with links fails for non elevated user if developer mode not
269269 Remove-Item - Path $testFilePath - Force - ErrorAction SilentlyContinue
270270 }
271271
272- It " Should error correctly when failing to create a symbolic link and not in developer mode" - Skip:(! $IsWindows -or $developerMode ) {
272+ It " Should error correctly when failing to create a symbolic link and not in developer mode" - Skip:(! $IsWindows -or $developerMode -or ( Test-IsElevated ) ) {
273273 { New-Item - ItemType SymbolicLink - Path $TestFilePath - Target $FullyQualifiedFile - ErrorAction Stop } |
274274 Should - Throw - ErrorId " NewItemSymbolicLinkElevationRequired,Microsoft.PowerShell.Commands.NewItemCommand"
275275 $TestFilePath | Should -Not - Exist
276276 }
277277
278- It " Should succeed to create a symbolic link without elevation and in developer mode" - Skip:(! $IsWindows -or ! $developerMode ) {
278+ It " Should succeed to create a symbolic link without elevation and in developer mode" - Skip:(! $IsWindows -or ! $developerMode -or ( Test-IsElevated ) ) {
279279 { New-Item - ItemType SymbolicLink - Path $TestFilePath - Target $FullyQualifiedFile - ErrorAction Stop } | Should -Not - Throw
280280 $TestFilePath | Should - Exist
281281 }
You can’t perform that action at this time.
0 commit comments