Guest User

Untitled

a guest
Nov 7th, 2020
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ############################################
  2. #
  3. # Developer: Max Jensen - www.maxjensen.dk
  4. # Updated: 05-11-2020
  5. #
  6. # Purpose: Set new wallpaper on current logged in user on remote computer and show to ne w wallpaper instantly
  7. #
  8. # Limitations:
  9. # Windows 10 not always refreshing wallpaper when set, using the command: rundll32.exe user32.dll, UpdatePerUserSystemParameters, 1, true
  10. # 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.
  11. #
  12. ############################################
  13.  
  14. Import-module ActiveDirectory
  15. $computer = Read-Host -Prompt 'Enter computername'
  16.  
  17. Write-Host -ForegroundColor Yellow "`r`nEnter your admin account here like DOMAIN\username...`r`n"
  18. $creds = Get-Credential
  19.  
  20. #encrypting password
  21. Write-Host -ForegroundColor Yellow "`r`n............................................`r`n"
  22. $b64 = Read-host 'Enter password you want to encrypt to base64'
  23. $encrypt = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes("$b64"))
  24. $decodeBase64 = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String("$encrypt"))
  25.  
  26. Write-Host -ForegroundColor Yellow "`r`nPassword set to:`r`n$decodeBase64"
  27.  
  28. $server = Read-host 'Enter server to copy data from'
  29. $destination = "C:\windows\temp\b.jpg"
  30.  
  31.  
  32. # Remote into client and do stuff...
  33. $Session = New-PSSession -ComputerName $computer -Credential $creds
  34. $Option = Read-Host "Type 1 for using photo FCK - eller Type 2 for using photo AALBORG"
  35.  
  36.  
  37. # Check if processes is active if yes, then kill them so we can continue script
  38.  
  39. $PSexec = Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC"}
  40. if ($PSexec) {
  41.   Write-Host -ForegroundColor Yellow "`r`nKilling PSEXEC service which was already running.. please wait!`r`n"
  42.   Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC" | Stop-Process -force}
  43.   if (!$PSexec.HasExited) {
  44.    Write-Host -ForegroundColor Yellow "`r`nKilling PSEXEC service which was already running.. please wait!`r`n"
  45.     Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC" | Stop-Process -force}
  46.   }
  47. }else{
  48.    Write-Host -ForegroundColor Yellow "`r`nNo PSEXEC service running in background.. moving on!`r`n"
  49.   }
  50.  
  51. C:\Drift\Sysinternals\PsExec.exe \\$computer -u $computer\administrator -p $decodeBase64 -i -d cmd /C "start /MIN powershell C:\tmp\refreshbg.ps1"
  52. Start-sleep 2
  53.  
  54. $SystemSettings = Invoke-command -ComputerName $computer -ScriptBlock {Get-process -name "SystemSettings" | Stop-Process -Force}
  55.  
  56. if ($SystemSettings) {
  57.   Write-Host -ForegroundColor Yellow "`r`nKilling SystemSettings service which was already running.. please wait!`r`n"
  58.   Invoke-command -ComputerName $computer -ScriptBlock {Get-process -name "SystemSettings" | Stop-Process -Force}
  59.   if (!$SystemSettings.HasExited) {
  60.    Write-Host -ForegroundColor Yellow "`r`nKilling SystemSettings service which was already running.. please wait!`r`n"
  61.     Invoke-command -ComputerName $computer -ScriptBlock {get-process -Name "PSEXESVC" | Stop-Process -force}
  62.   }
  63. }else{
  64.    Write-Host -ForegroundColor Yellow "`r`nNo SystemSettings service running in background.. moving on!`r`n"
  65.   }
  66.   Start-sleep 2
  67.  
  68.  
  69.  
  70. #### Select correct photo and if folder not created then create it on the client
  71. if($Option -eq "1"){
  72. Write-Host -ForegroundColor Yellow "`r`nYou picked the photo - FCK!...`r`n"
  73. Write-Host -ForegroundColor Cyan "`r`n--------------------------------------------`r`n"
  74.  
  75. $path = "\\$computer\C$\tmp"
  76. If(!(test-path $path))
  77. {
  78.       New-Item -ItemType Directory -Force -Path $path
  79. }
  80.  
  81. Copy-Item -Path "\\$server\C$\tmp\FCK.jpg" -Destination "\\$computer\C$\windows\temp\b.jpg" -force
  82. Copy-Item -Path "\\$server\C$\tmp\refreshbg.ps1" -Destination "\\$computer\C$\tmp\refreshbg.ps1" -force
  83. Copy-Item -Path "\\$server\C$\tmp\newtheme-coop.theme" -Destination "\\$computer\C$\tmp\newtheme-coop.theme" -force
  84.  
  85. }
  86.  
  87. if($Option -eq "2"){
  88. Write-Host -ForegroundColor Yellow "`r`nYou picked the photo - AALBORG!...`r`n"
  89. Write-Host -ForegroundColor Cyan "`r`n--------------------------------------------`r`n"
  90.  
  91. $path = "\\$computer\C$\tmp"
  92. If(!(test-path $path))
  93. {
  94.       New-Item -ItemType Directory -Force -Path $path
  95. }
  96.  
  97. Copy-Item -Path "\\$server\C$\tmp\aalborg.jpg" -Destination "\\$computer\C$\windows\temp\b.jpg" -force
  98. Copy-Item -Path "\\$server\C$\tmp\refreshbg.ps1" -Destination "\\$computer\C$\tmp\refreshbg.ps1" -force
  99. Copy-Item -Path "\\$server\C$\tmp\newtheme.theme" -Destination "\\$computer\C$\tmp\newtheme.theme" -force
  100.  
  101. }
  102.  
  103. Write-Host -ForegroundColor Yellow "`r`nEnter your admin account here!... `r`n"
  104. Enter-PSSession -Credential $creds -ComputerName $computer
  105.  
  106. # this part I am not sure work proper ....
  107. $users = Invoke-Command -ScriptBlock {Get-ChildItem "C:\users"| ? { $_.psiscontainer } | % { $_.Name }}
  108. $sid = Get-Item Registry::HKEY_USERS | Where-Object {$_.Name -match $PatternSID} |? { $_.psiscontainer } | % { $_.Name }
  109.  
  110. foreach($user in $sid){
  111.  
  112. Invoke-Command -ScriptBlock {set-ItemProperty -path "HKCU:\$user\Control Panel\Desktop\" -name wallpaper -value "C:\windows\temp\b.jpg" -force}
  113. Invoke-Command -ScriptBlock {Set-ItemProperty -path "Registry::\HKEY_USERS\$user\Control Panel\Desktop" -name wallpaper -value "C:\windows\temp\b.jpg" -force}
  114. Invoke-Command -ScriptBlock {Set-ItemProperty -path "Registry::\HKEY_CURRENT_USER\Control Panel\Desktop" -name wallpaper -value "C:\windows\temp\b.jpg" -force}
  115.  
  116. }
  117. # end of test which I am not sure working
  118.  
  119. Write-Host -ForegroundColor Yellow "`r`nWe're done here.. closing session `r`n"
  120. Exit-PSSession
  121. Get-PSSession | select id | Remove-PSSession
  122.  
  123. Write-Host -ForegroundColor Yellow "`r`nUpdating background!... please wait!`r`n"
  124. Start-Sleep 2
  125.  
  126. C:\sysinternals\PsExec.exe \\$computer -u domain\administrator -p $decodeBase64 -i -d cmd /C "start /MIN powershell C:\tmp\refreshbg.ps1"
  127. Start-sleep 2
  128. C:\sysinternals\psexec.exe \\$computer -u domain\administrator -p $decodeBase64 -i -d cmd /C "RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True"
  129. Start-sleep 2
  130. C:\sysinternals\PsExec.exe \\$computer -u domain\administrator -p $decodeBase64 -i -d cmd /C "C:\tmp\newtheme.theme"
  131. Start-sleep 2
  132. 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}"
  133. Invoke-command -ComputerName $computer -ScriptBlock {Get-process -name "SystemSettings" | Stop-Process -Force}
  134. Write-Host -ForegroundColor Yellow "`r`nBackground now changed!`r`n"
Add Comment
Please, Sign In to add comment