Advertisement
Guest User

Untitled

a guest
Nov 5th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function RecycleBinDeleteConfirmation
  2. {
  3.     param
  4.     (
  5.         [Parameter()]
  6.         [switch]
  7.         $Enable,
  8.  
  9.         [Parameter()]
  10.         [switch]
  11.         $Disable
  12.     )
  13.  
  14.     if ($Enable.IsPresent)
  15.     {
  16.         $ShellState = Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState
  17.         $ShellState[4] = 51
  18.     }
  19.  
  20.     if ($Disable.IsPresent)
  21.     {
  22.         $ShellState = Get-ItemPropertyValue -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState
  23.         $ShellState[4] = 55
  24.     }
  25.  
  26.     New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name ShellState -PropertyType Binary -Value $ShellState -Force
  27.  
  28.     $UpdateDesktop = @{
  29.         Namespace = "WinAPI"
  30.         Name = "UpdateDesktop"
  31.         Language = "CSharp"
  32.         MemberDefinition = @"
  33. private static readonly IntPtr hWnd = new IntPtr(65535);
  34. private const int Msg = 273;
  35. // Virtual key ID of the F5 in File Explorer
  36. // Виртуальный код клавиши F5 в проводнике
  37. private static readonly UIntPtr UIntPtr = new UIntPtr(41504);
  38.  
  39. [DllImport("user32.dll", SetLastError=true)]
  40. public static extern int PostMessageW(IntPtr hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);
  41. public static void PostMessage()
  42. {
  43.     // F5 pressing simulation to refresh the desktop
  44.     // Симуляция нажатия F5 для обновления рабочего стола
  45.     PostMessageW(hWnd, Msg, UIntPtr, IntPtr.Zero);
  46. }
  47. "@
  48.     }
  49.     if (-not ("WinAPI.UpdateDesktop" -as [type]))
  50.     {
  51.         Add-Type @UpdateDesktop
  52.     }
  53.  
  54.     # Send F5 pressing simulation to refresh the desktop
  55.     # Симулировать нажатие F5 для обновления рабочего стола
  56.     [WinAPI.UpdateDesktop]::PostMessage()
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement