Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # settings, 0 = use default
- [string] $targetimagename = "client.exe"
- [int] $targetwidth = 0
- [int] $targetheight = 0
- [int] $targetdisplay = 0
- [int] $borderfix = 0
- # load System.Windows
- $void = [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- # import c#
- Add-Type -Language CSharpVersion3 @"
- using System;
- using System.Runtime.InteropServices;
- public class WindowUtil
- {
- [StructLayout(LayoutKind.Sequential)]
- public struct RECT
- {
- public int Left;
- public int Top;
- public int Right;
- public int Bottom;
- }
- [DllImport("user32.dll")]
- public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
- [DllImport("user32.dll")]
- public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
- [DllImport("user32.dll")]
- public static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
- [DllImport("user32.dll")]
- public static extern bool SetWindowPos(IntPtr hWnd,
- int hWndInsertAfter, int X,int Y, int cx, int cy, uint uFlags);
- public static void MaximizeWindow(IntPtr hWnd, int w, int h, int fix)
- {
- RECT inner, outer;
- ShowWindow(hWnd, 1 /* restore and activate */);
- GetClientRect(hWnd, out inner);
- GetWindowRect(hWnd, out outer);
- int border = (outer.Right - outer.Left) - (inner.Right - inner.Left);
- int titlebar = (outer.Bottom - outer.Top) - (inner.Bottom - inner.Top) - border;
- border = border / 2 - fix;
- SetWindowPos(hWnd, 1/*HWND_TOPMOST*/,
- -border, -border - titlebar, w + border * 2, h + titlebar + border * 2,
- 0x0400/*SWP_NOSENDCHANGING*/);
- }
- }
- "@
- # set screen size
- Function GetScreenSize
- {
- $screens = [System.Windows.Forms.Screen]::AllScreens
- if (($targetdisplay -le 0) -or ($targetdisplay -gt $screens.Count)) {
- $screen = $screens[0]
- } else {
- $screen = $screens[$targetdisplay - 1];
- }
- #"Screen Resolution: {0}x{1}" -f $screen.Bounds.Width, $screen.Bounds.Height
- if ($targetwidth -eq 0) {
- $global:targetwidth = $screen.Bounds.Width
- }
- if ($targetheight -eq 0) {
- $global:targetheight = $screen.Bounds.Height
- }
- }
- GetScreenSize
- [int] $found = 0
- get-process | foreach-object -process {
- if ($_.MainModule.ModuleName -eq $targetimagename) {
- [WindowUtil]::MaximizeWindow($_.MainWindowHandle, $targetwidth, $targetheight, $borderfix)
- $found++
- }
- }
- "Found {0} matches" -f $found
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement