maximize window in different session

Nov 7, 2014 at 11:18 PM
I am trying to run a PS script to maximize a specific application if it is not currently maximized.
I am currently just looking at the window width to determine the state, if anyone knows a better way please ley me know.

the issue im having is that the script is being run through a remote monitoring app that runs under the SYSTEM account and it forces powershell to run as the same user. because of this my script doesn't work.

this is my script

Add-PSSnapin WASP
$s = select-window 'notepad'
$n = select-window 'notepad' | get-windowposition | Format-Wide -Property Width
if ($n -notcontains 1920)
{
  $s | set-windowposition -Maximize
}
and I have tried launching it via CMD and PS
/c PowerShell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\WASP\maximize.ps1""' -Verb RunAs}"

I know its running because I can change it to
[Environment]::UserName | out-file c:\wasp\test.txt

and it outputs SYSTEM...


any ideas on how to get this to run under the currently logged in user?
Coordinator
Nov 9, 2014 at 3:54 AM
I think invoking code "as" the user from system would be a violation of a security boundry ... you'd have to get credentials.

At that point it's a generic problem, and there are lot's of suggestions for how to run scripts as another user out there ;-)

Personally, I think the simplest thing is to use a scheduled task with stored credentials, but I don't know what your exact use case is.