Automātiska darbvirsmas attēla maiņa
Uzstādīšanas ceļš
C:\Users\Skolnieks\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\
.
├─📂Programs
| ├─📂Startup
| | └─ run.bat
| ├─📂run_wallpaper
| | ├─ wallpaper.png
| | └─ run.ps1
Batch kods
batch
@echo off
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& 'C:\Users\Skolnieks\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\run_wallpaper\run.ps1'"
exit 0
PowerShell kods
powershell
$setwallpapersrc = @"
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 $setwallpapersrc
# Path to wallpaper
[Wallpaper]::SetWallpaper("C:\Users\Skolnieks\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\run_wallpaper\wallpaper.png")
Failu rezerves kopēšanas sistēma
Uzstādīšanas ceļš
C:\Users\test\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
.
├─📂Programs
| ├─📂Startup
| | └─ backup_system.bat
| └─ backup_system.ps1
Batch kods
batch
@echo off
powershell -ExecutionPolicy Bypass -File "C:\Users\Skolnieks\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\backup_system.ps1" -WindowStyle Hidden
exit
PowerShell kods
powershell
# Full path to the Documents directory
$sourceDir = "C:\Users\Skolnieks\Documents"
# Path to the backup directory
$backupDir = "C:\Users\Skolnieks\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\BackupDocuments"
# File extensions to delete from Desktop and Documents
$fileExtensionsDesktop = @(".docx", ".pptx", ".xlsx", ".png", ".jpg", ".webp", ".html", ".css", ".js", ".txt", ".bmp", ".jpeg", ".rtf", ".mov", ".mp4", ".avi", ".mkv", ".bat", ".exe")
$fileExtensionsDocuments = @(".mov", ".mp4", ".avi", ".mkv", ".bat", ".exe")
# Function to delete files and folders from the desktop
function Remove-FilesFromDesktop {
$desktopPath = "C:\Users\Skolnieks\Desktop"
# Delete files with specified extensions
foreach ($extension in $fileExtensionsDesktop) {
Get-ChildItem -Path $desktopPath -Include "*$extension" -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue
}
# Delete all folders on the desktop
Get-ChildItem -Path $desktopPath -Directory | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
}
# Function to delete specific file types from Documents and all subdirectories
function Remove-VideoAndExecutableFiles {
foreach ($extension in $fileExtensionsDocuments) {
Get-ChildItem -Path $sourceDir -Include "*$extension" -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue
}
}
# Remove unnecessary files and folders from the desktop
Remove-FilesFromDesktop
# Remove video and executable files from Documents
Remove-VideoAndExecutableFiles
# Create the backup directory if it doesn't exist
if (-not (Test-Path -Path $backupDir)) {
New-Item -ItemType Directory -Path $backupDir -Force
}
# Copy new and changed files from the working directory to the backup
# /E - copies all subdirectories including empty ones
# /XO - excludes older files from being copied
# /R:2 - 2 attempts to copy
# /W:5 - waits 5 seconds before retrying
# /XD - excludes the backup directory from copying
# /XJ - excludes symbolic links
robocopy $sourceDir $backupDir /E /XO /R:2 /W:5 /XD $backupDir /XJ
# Restore files if they were deleted from the working directory but exist in the backup
robocopy $backupDir $sourceDir /E /XO /R:2 /W:5 /XD $sourceDir /XJ
# Remove only files at the top level of the Documents directory, but do not touch folders or files inside folders
Get-ChildItem -Path $sourceDir -File | Remove-Item -Force -ErrorAction SilentlyContinue
# Remove only files at the top level of the backup directory, but do not touch folders or files inside folders
Get-ChildItem -Path $backupDir -File | Remove-Item -Force -ErrorAction SilentlyContinue