1
1
# Credit: https://superuser.com/a/1343640
2
2
$imagePath = " $env: windir \AtlasModules\Wallpapers\lockscreen.png"
3
3
4
- $newImagePath = $ ( Split- Path $imagePath ) + ' \' + (New-Guid ).Guid + [System.IO.Path ]::GetExtension($imagePath )
4
+ $newImagePath = [ System.IO. Path]::GetDirectoryName( $imagePath ) + ' \' + (New-Guid ).Guid + [System.IO.Path ]::GetExtension($imagePath )
5
5
Copy-Item $imagePath $newImagePath
6
6
[Windows.System.UserProfile.LockScreen , Windows.System.UserProfile , ContentType = WindowsRuntime ] | Out-Null
7
7
Add-Type - AssemblyName System.Runtime.WindowsRuntime
8
8
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions ].GetMethods() | ? { $_.Name -eq ' AsTask' -and $_.GetParameters ().Count -eq 1 -and $_.GetParameters ()[0 ].ParameterType.Name -eq ' IAsyncOperation`1' })[0 ]
9
- function Await ($WinRtTask , $ResultType ) {
9
+ Function Await ($WinRtTask , $ResultType ) {
10
10
$asTask = $asTaskGeneric.MakeGenericMethod ($ResultType )
11
11
$netTask = $asTask.Invoke ($null , @ ($WinRtTask ))
12
12
$netTask.Wait (-1 ) | Out-Null
13
13
$netTask.Result
14
14
}
15
- function AwaitAction ($WinRtAction ) {
15
+ Function AwaitAction ($WinRtAction ) {
16
16
$asTask = ([System.WindowsRuntimeSystemExtensions ].GetMethods() | ? { $_.Name -eq ' AsTask' -and $_.GetParameters ().Count -eq 1 -and ! $_.IsGenericMethod })[0 ]
17
17
$netTask = $asTask.Invoke ($null , @ ($WinRtAction ))
18
18
$netTask.Wait (-1 ) | Out-Null
19
19
}
20
20
[Windows.Storage.StorageFile , Windows.Storage , ContentType = WindowsRuntime ] | Out-Null
21
- $image = Await ([Windows.Storage.StorageFile ]::GetFileFromPathAsync(" $env: windir \AtlasModules\Wallpapers\lockscreen.png" )) ([Windows.Storage.StorageFile ])
22
- AwaitAction ([Windows.System.UserProfile.LockScreen ]::SetImageFileAsync($image ))
21
+ $image = Await ([Windows.Storage.StorageFile ]::GetFileFromPathAsync($newImagePath )) ([Windows.Storage.StorageFile ])
22
+ AwaitAction ([Windows.System.UserProfile.LockScreen ]::SetImageFileAsync($image ))
23
+ Remove-Item $newImagePath
0 commit comments