powershell scripts

Pcgamer27

Member
Messages
168
Reaction score
1
I have a problem, I want to run a powershell script and I always get the message that the file cannot be found, does anyone know what is happening?
 
The only thing that comes to mind is that the file indicated in the script is not in the location indicated
 
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?

# 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
 
Back
Top