This script automates the process of capturing a photo using the Windows Camera app, saving it to the Camera Roll folder, and setting it as the desktop wallpaper.
- Windows operating system.
- Windows Camera app installed.
- PowerShell scripting environment.
Download the Script: Download the CSP.ps1 script to your local machine.
Run the Script: Right-click on the script file and select "Run with PowerShell" to execute the script. Alternatively, you can open PowerShell, navigate to the directory where the script is located, and run it using the command .\CSP.ps1.
Follow On-Screen Prompts: The script will start the Windows Camera app, take a photo, save it to the Camera Roll folder, and set it as the desktop wallpaper. Follow any on-screen prompts if necessary.
Review Output: After execution, check your desktop background to verify that the new photo has been set as the wallpaper.
Ensure that the Windows Camera app is properly installed and functional before running the script. Make sure to grant necessary permissions for the script to access system folders and execute commands. Customize the script variables such as $newCameraRollPath to specify your desired location for the Camera Roll folder. This script may need to be run with administrative privileges depending on system configurations. Troubleshooting Error Handling: If any errors occur during execution, the script will display error messages and prompt you to press any key to continue. Review the error messages to troubleshoot issues. Permissions: Ensure that the user running the script has necessary permissions to access system folders and execute PowerShell commands. Camera App Issues: If the Windows Camera app does not function as expected, troubleshoot any app-related issues separately. File Operations: If the script fails during file operations (copying photos, setting wallpaper), ensure that the specified paths are correct and accessible. Disclaimer This script is provided as-is without any warranty. Use it at your own risk. The author is not responsible for any damages caused by the use or misuse of this script.
This script was authored by VBV11.
trap { Write-Host "An error occurred:`n$($_.Exception.Message)" Write-Host "Press any key to continue..." $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown') }
function Set-CameraRollPath { param ( [string]$newPath )
# Setting the new camera roll path
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" -Name "{AB5FB87B-7CE2-4F83-915D-550846C9537B}" -Value $newPath
# Refresh the shell
$null = (New-Object -ComObject Shell.Application).NameSpace(0).Self.InvokeVerb("Ref&resh")
}
$newCameraRollPath = "$env:userprofile\Pictures\CameraRoll"
if (-not (Test-Path -Path $newCameraRollPath)) { New-Item -ItemType Directory -Path $newCameraRollPath }
Set-CameraRollPath -newPath $newCameraRollPath
Start-Process "microsoft.windows.camera:" -WindowStyle Maximized -ErrorAction Stop
Start-Sleep -Seconds 5
Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.SendKeys]::SendWait("{Enter}")
Start-Sleep -Seconds 5
Get-Process "WindowsCamera" | Stop-Process -Force
Start-Sleep -Seconds 2
$cameraRollPath = $newCameraRollPath
$latestPhoto = Get-ChildItem $cameraRollPath | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if (-not $latestPhoto) { throw "Unable to find a photo in the Camera Roll folder." }
$desktopPath = [Environment]::GetFolderPath("Desktop")
$fileName = "photo_" + (Get-Date -Format "yyyyMMdd_HHmmss") + ".jpg"
Move-Item $latestPhoto.FullName -Destination (Join-Path -Path $desktopPath -ChildPath $fileName) -Force -ErrorAction Stop
$code = @' using System.Runtime.InteropServices; namespace Win32 {
public class Wallpaper {
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
public static void SetWallpaper(string thePath) {
SystemParametersInfo(20, 0, thePath, 3);
}
}
} '@
Add-Type $code
$imagePath = "$env:TEMP\image.jpg"
Copy-Item (Join-Path -Path $desktopPath -ChildPath $fileName) -Destination $imagePath -Force -ErrorAction Stop
[Win32.Wallpaper]::SetWallpaper($imagePath)