Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ############################################
- #
- # Developer: Max Jensen - www.maxjensen.dk
- # Updated: 05-11-2020
- #
- # Purpose: Set new wallpaper on current logged in user on remote computer and show to ne w wallpaper instantly
- #
- # Limitations:
- # Windows 10 not always refreshing wallpaper when set, using the command: rundll32.exe user32.dll, UpdatePerUserSystemParameters, 1, true
- # We instead have to use a new theme by copy that to the client and load it with psexec to present it to the user instantly without logoff or restart.
- #
- ############################################
- Import-module ActiveDirectory
- $computer = Read-Host -Prompt 'Enter computername'
- Write-Host -ForegroundColor Yellow "`r`nEnter your admin account here like DOMAIN\username...`r`n"
- $creds = Get-Credential
- #encrypting password
- Write-Host -ForegroundColor Yellow "`r`n............................................`r`n"
- $b64 = Read-host 'Enter password you want to encrypt to base64'
- $encrypt = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("$b64"))
- $decodeBase64 = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String("$encrypt"))
- Write-Host -ForegroundColor Yellow "`r`nPassword set to:`r`n$decodeBase64"
- $server = Read-host 'Enter server to copy data from'
- $destination = "C:\windows\temp\b.jpg"
- # Remote into client and do stuff...
- $Session = New-PSSession -ComputerName $computer -Credential $creds
- $Option = Read-Host "Type 1 for using photo FCK - eller Type 2 for using photo AALBORG"
- # Check if processes is active if yes, then kill them so we can continue script
- $PSexec = Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC"}
- if ($PSexec) {
- Write-Host -ForegroundColor Yellow "`r`nKilling PSEXEC service which was already running.. please wait!`r`n"
- Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC" | Stop-Process -force}
- if (!$PSexec.HasExited) {
- Write-Host -ForegroundColor Yellow "`r`nKilling PSEXEC service which was already running.. please wait!`r`n"
- Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC" | Stop-Process -force}
- }
- }else{
- Write-Host -ForegroundColor Yellow "`r`nNo PSEXEC service running in background.. moving on!`r`n"
- }
- C:\Drift\Sysinternals\PsExec.exe \\$computer -u $computer\administrator -p $decodeBase64 -i -d cmd /C "start /MIN powershell C:\tmp\refreshbg.ps1"
- Start-sleep 2
- $SystemSettings = Invoke-command -ComputerName $computer -ScriptBlock {Get-process -name "SystemSettings" | Stop-Process -Force}
- if ($SystemSettings) {
- Write-Host -ForegroundColor Yellow "`r`nKilling SystemSettings service which was already running.. please wait!`r`n"
- Invoke-command -ComputerName $computer -ScriptBlock {Get-process -name "SystemSettings" | Stop-Process -Force}
- if (!$SystemSettings.HasExited) {
- Write-Host -ForegroundColor Yellow "`r`nKilling SystemSettings service which was already running.. please wait!`r`n"
- Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC" | Stop-Process -force}
- }
- }else{
- Write-Host -ForegroundColor Yellow "`r`nNo SystemSettings service running in background.. moving on!`r`n"
- }
- Start-sleep 2
- #### Select correct photo and if folder not created then create it on the client
- if($Option -eq "1"){
- Write-Host -ForegroundColor Yellow "`r`nYou picked the photo - FCK!...`r`n"
- Write-Host -ForegroundColor Cyan "`r`n--------------------------------------------`r`n"
- $path = "\\$computer\C$\tmp"
- If(!(test-path $path))
- {
- New-Item -ItemType Directory -Force -Path $path
- }
- Copy-Item -Path "\\$server\C$\tmp\FCK.jpg" -Destination "\\$computer\C$\windows\temp\b.jpg" -force
- Copy-Item -Path "\\$server\C$\tmp\refreshbg.ps1" -Destination "\\$computer\C$\tmp\refreshbg.ps1" -force
- Copy-Item -Path "\\$server\C$\tmp\newtheme-coop.theme" -Destination "\\$computer\C$\tmp\newtheme-coop.theme" -force
- }
- if($Option -eq "2"){
- Write-Host -ForegroundColor Yellow "`r`nYou picked the photo - AALBORG!...`r`n"
- Write-Host -ForegroundColor Cyan "`r`n--------------------------------------------`r`n"
- $path = "\\$computer\C$\tmp"
- If(!(test-path $path))
- {
- New-Item -ItemType Directory -Force -Path $path
- }
- Copy-Item -Path "\\$server\C$\tmp\aalborg.jpg" -Destination "\\$computer\C$\windows\temp\b.jpg" -force
- Copy-Item -Path "\\$server\C$\tmp\refreshbg.ps1" -Destination "\\$computer\C$\tmp\refreshbg.ps1" -force
- Copy-Item -Path "\\$server\C$\tmp\newtheme.theme" -Destination "\\$computer\C$\tmp\newtheme.theme" -force
- }
- Write-Host -ForegroundColor Yellow "`r`nEnter your admin account here!... `r`n"
- Enter-PSSession -Credential $creds -ComputerName $computer
- # this part I am not sure work proper ....
- $users = Invoke-Command -ScriptBlock {Get-ChildItem "C:\users"| ? { $_.psiscontainer } | % { $_.Name }}
- $sid = Get-Item Registry::HKEY_USERS | Where-Object {$_.Name -match $PatternSID} |? { $_.psiscontainer } | % { $_.Name }
- foreach($user in $sid){
- Invoke-Command -ScriptBlock {set-ItemProperty -path "HKCU:\$user\Control Panel\Desktop\" -name wallpaper -value "C:\windows\temp\b.jpg" -force}
- Invoke-Command -ScriptBlock {Set-ItemProperty -path "Registry::\HKEY_USERS\$user\Control Panel\Desktop" -name wallpaper -value "C:\windows\temp\b.jpg" -force}
- Invoke-Command -ScriptBlock {Set-ItemProperty -path "Registry::\HKEY_CURRENT_USER\Control Panel\Desktop" -name wallpaper -value "C:\windows\temp\b.jpg" -force}
- }
- # end of test which I am not sure working
- Write-Host -ForegroundColor Yellow "`r`nWe're done here.. closing session `r`n"
- Exit-PSSession
- Get-PSSession | select id | Remove-PSSession
- Write-Host -ForegroundColor Yellow "`r`nUpdating background!... please wait!`r`n"
- Start-Sleep 2
- C:\sysinternals\PsExec.exe \\$computer -u domain\administrator -p $decodeBase64 -i -d cmd /C "start /MIN powershell C:\tmp\refreshbg.ps1"
- Start-sleep 2
- C:\sysinternals\psexec.exe \\$computer -u domain\administrator -p $decodeBase64 -i -d cmd /C "RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True"
- Start-sleep 2
- C:\sysinternals\PsExec.exe \\$computer -u domain\administrator -p $decodeBase64 -i -d cmd /C "C:\tmp\newtheme.theme"
- Start-sleep 2
- C:\sysinternals\PsExec.exe \\$computer -u domain\administrator -p $decodeBase64 -i -d cmd /C "start /MIN powershell for($i=1;$i -le 50;$i++){rundll32.exe user32.dll, UpdatePerUserSystemParameters, 1, true}"
- Invoke-command -ComputerName $computer -ScriptBlock {Get-process -name "SystemSettings" | Stop-Process -Force}
- Write-Host -ForegroundColor Yellow "`r`nBackground now changed!`r`n"
Add Comment
Please, Sign In to add comment