Advertisement
kolyaventuri

Succ.ps1

Feb 6th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $progressPreference = 'silentlyContinue';
  2. $tmp = -join ((65..90) + (97..122) | Get-Random -Count 8 | % {[char]$_});
  3.  
  4. $f1 = "https://enx3s.com/files/succ.jpg";
  5. $f2 = "https://enx3s.com/files/succ.wav";
  6. New-Item "C:\$tmp" -type directory | Out-Null;
  7. $script:nativeMethods = @();
  8.  
  9. function Register-NativeMethod([string]$dll, [string]$methodSignature)
  10. {
  11.     $script:nativeMethods += [PSCustomObject]@{
  12.         Dll = $dll;
  13.         Signature = $methodSignature;
  14.     };
  15. };
  16.  
  17. function Add-NativeMethods()
  18. {
  19.     $nativeMethodsCode = $script:nativeMethods | % {
  20.         "[DllImport(`"$($_.Dll)`")] public static extern $($_.Signature);";
  21.     };
  22.  
  23.     Add-Type "using System; using System.Runtime.InteropServices; public static class User32 {$nativeMethodsCode}";
  24. };
  25.  
  26. # Load in native DLL functions
  27. Register-NativeMethod "user32.dll" "IntPtr GetDC(IntPtr hwnd)";
  28. Register-NativeMethod "user32.dll" "void ReleaseDC(IntPtr hwnd, IntPtr dc)";
  29. Add-NativeMethods;
  30.  
  31. Add-Type -AssemblyName System.Windows.Forms;
  32. $screens = [System.Windows.Forms.Screen]::AllScreens;
  33. foreach($screen in $screens) {
  34.     if($screen.Primary) {
  35.         $primary = $screen;
  36.     }
  37. };
  38.  
  39. # This is how we load assemblies
  40. [void] [System.Reflection.Assembly]::LoadWithPartialName("System");
  41. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing");
  42. [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Media");
  43.  
  44. # Create call functions to init variables
  45. [System.IntPtr] $desk = [User32]::GetDC([System.IntPtr]::Zero);
  46. [System.Drawing.Graphics] $graphics = [System.Drawing.Graphics]::FromHdc($desk);
  47.  
  48. # Download files
  49. Invoke-WebRequest -OutFile "C:\$tmp\succ.jpg" $f1 | Out-Null;
  50. Invoke-WebRequest -OutFile "C:\$tmp\succ.wav" $f2 | Out-Null;
  51.  
  52. # Various variable initiations
  53. $image = [Drawing.Image]::FromFile("C:\$tmp\succ.jpg"); #Equivalent to Drawing.Image.FromFile(string file)
  54. $factor  = 0.75;
  55. $w = $image.Width * $factor;
  56. $h = $image.Height * $factor;
  57. $x =  ($primary.Bounds.Width / 2) - ($w / 2) + $primary.Bounds.X;
  58. $y = ($primary.Bounds.Height / 2) - ($h / 2) + $primary.Bounds.Y;
  59. $rect = New-Object Drawing.Rectangle $x, $y, $w, $h;
  60. [System.Media.SoundPlayer] $player = [System.Media.SoundPlayer]("C:\$tmp\succ.wav");
  61.  
  62. # Draw the image and play sound
  63. $graphics.DrawImage($image, $rect);
  64. $player.PlaySync();$graphics.Dispose();$image.Dispose();
  65. [User32]::ReleaseDC([System.IntPtr]::Zero, $desk);
  66.  
  67. Remove-Item "C:\$tmp" -Force -Recurse;
  68. exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement