Merhabalar powershell resim indirme ve arkaplan olarak ayarlama konusun birşeyler paylaşmak istedim.
Kabuğumun dışına çıkarak ofisimizde ihtiyacımız olan işlemin kolaylaştırmasını sağlamak amacı ile birden fazla bilgisaayarın arkaplan resimlerini tek tek değiştirmek yerine powershell script ile otomatik olarak belirttiğimiz yerdeki resmi çekerek arkaplan yapmasını sağlamak için bir kod hazırladık bunu sizlerlede paylaşmak istedim.
[code]
function getfile($url, $filename)
{
$wc = New-Object System.Net.WebClient
Register-ObjectEvent -InputObject $wc -EventName DownloadProgressChanged -SourceIdentifier WebClient.DownloadProgressChanged -Action { Write-Progress -Activity "Downloading: $($EventArgs.ProgressPercentage)% Completed" -Status $url -PercentComplete $EventArgs.ProgressPercentage; }
Register-ObjectEvent -InputObject $wc -EventName DownloadFileCompleted -SourceIdentifier WebClient.DownloadFileComplete -Action { Write-Host "Download Complete – $filename"; Unregister-Event -SourceIdentifier WebClient.DownloadProgressChanged; Unregister-Event -SourceIdentifier WebClient.DownloadFileComplete; }
try
{
$wc.DownloadFileAsync($url, $filename)
}
catch [System.Net.WebException]
{
Write-Host("Cannot download $url")
}
finally
{
$wc.Dispose()
}
}
$url = "https://www.planwallpaper.com/static/images/i-should-buy-a-boat.jpg"
$filename = "c:\serenity.jpg"
getfile $url $filename
set-itemproperty -path "HKCU:Control Panel\Desktop" -name WallPaper -value $filename
rundll32.exe user32.dll, UpdatePerUserSystemParameters, 1 , True
$setwallpapersource = @"
using System.Runtime.InteropServices;
public class wallpaper
{
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path )
{
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange );
}
}
"@
Add-Type -TypeDefinition $setwallpapersource
[wallpaper]::SetWallpaper("c:\serenity.jpg")
[/code]
Newtork üzerinden resim alarak ayarlama
Ekstra olarak network üzerinden resim alarak arkaplan olarak ayarlayıp sığdırma (fit) işlemi için ise aşağıdaki kodu kullanabilirsiniz.
[code]
New-PSDrive -Name S -Root \\192.168.1.85\smartboards\ -PSProvider FileSystem
Write-Output "Copying Backups"
copy S:\tahta.jpg c:\tahta.jpg
$setwallpapersource = @"
using System.Runtime.InteropServices;
public class wallpaper
{
public const int SetDesktopWallpaper = 20;
public const int UpdateIniFile = 0x01;
public const int SendWinIniChange = 0x02;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper ( string path )
{
SystemParametersInfo( SetDesktopWallpaper, 10, path, UpdateIniFile | SendWinIniChange );
}
}
"@
#Add-Type -TypeDefinition $setwallpapersource
#[wallpaper]::SetWallpaper("c:\tahta.jpg")
Function Set-WallPaper($Value)
{
Set-ItemProperty -path ‘HKCU:\Control Panel\Desktop\’ -name wallpaper -value $value
Set-ItemProperty -path ‘HKCU:\Control Panel\Desktop\’ -name wallpaperstyle -value 6
rundll32.exe user32.dll, UpdatePerUserSystemParameters
}
Set-WallPaper -value "c:\tahta.jpg"
[/code]
sizde powershell resim indirme ve arkaplan olarak ayarlama scriptini kullanarak birden fazla bilgisayarınızın aynı anda arkaplan resimlerini güncelleyebilirsiniz.
Bilmeyenler için Microsoft powershell nedir için linki inceleyebilirsiniz.
Çok iyi anlatmışsın eline sağlık.