- Thread Author
- #1
I have a problem I have a script that only uses the URL to change the wallpaper but I have this locally. How can I do this? for NTlite software
# Define the URL for the wallpaper
$url = 'https://images.alphacoders.com/137/1377548.png'
$outputPath = "$env:TEMP\wallpaper.png"
try {
# Download the wallpaper
Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 30 -OutFile $outputPath
# Function to set wallpaper
function Set-Wallpaper {
param (
[string]$ImagePath
)
Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
public class Wallpaper {
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fWinIni);
public static void Set(string path) {
Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "2"); // Center
Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "0");
SystemParametersInfo(20, 0, path, 3);
}
}
"@
[Wallpaper]::Set($ImagePath)
}
# Set the downloaded image as wallpaper
Set-Wallpaper -ImagePath $outputPath
# Clean up
Remove-Item $outputPath -ErrorAction SilentlyContinue
exit 0
}
catch {
Write-Error "Failed to download or set wallpaper: $_"
exit 1
# Define the URL for the wallpaper
$url = 'https://images.alphacoders.com/137/1377548.png'
$outputPath = "$env:TEMP\wallpaper.png"
try {
# Download the wallpaper
Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 30 -OutFile $outputPath
# Function to set wallpaper
function Set-Wallpaper {
param (
[string]$ImagePath
)
Add-Type @"
using System;
using System.Runtime.InteropServices;
using Microsoft.Win32;
public class Wallpaper {
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fWinIni);
public static void Set(string path) {
Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "WallpaperStyle", "2"); // Center
Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Desktop", "TileWallpaper", "0");
SystemParametersInfo(20, 0, path, 3);
}
}
"@
[Wallpaper]::Set($ImagePath)
}
# Set the downloaded image as wallpaper
Set-Wallpaper -ImagePath $outputPath
# Clean up
Remove-Item $outputPath -ErrorAction SilentlyContinue
exit 0
}
catch {
Write-Error "Failed to download or set wallpaper: $_"
exit 1