Need help to make WASP module "ultra-portable"

Oct 11, 2013 at 7:47 PM
I'm not sue how other people use WASP; but, I'm trying to find out how to run my my WASP-dependent scripts on any Win7/win8 PC; even if it doesnt have WASP module already installed.

An Internet based packaging installer wouldn't really work since some PCs may not have Internet access.

I have considered to use "System.Windows.UIAutomation" from within PowerShell; so there's no dependency for WASP at all; but, unfortunately it t looks like accessing .NET functionality via Powershell isn't very intuitive. I haven't been able to find sample Powershell scripts which clearly demonstrate how to the basic common automation tasks below via .NET. I wasn't able to figure out how to do it by looking at the WASP module code unfortunately.
  • Minimize Window (title or process)
  • Maximize Window (title or process)
  • Resize Window (title or process)
  • Hide Window (title or process)
  • Activate Window (title or process)
  • Sendkey special characters such Windows-logo-Key+CTRL+ALT+F8
If there are no sample scripts, then it would be great if there was a Powershell script compiling tool which can embed file dependencies in the EXE; and, extract the file dependencies upon execution (same way done in AutoIt or other 3rd pary tools for "compiling" batch files or VB Scripts). I haven't found such a solution for that either.

Any useful help would be greatly appreciated!
Coordinator
Oct 14, 2013 at 4:52 AM
Edited Oct 14, 2013 at 6:25 PM
If you want something really minimal, you need to use the pure-script WASP 2 module.

The module is still in beta, and the PoshCode installer is still in beta (and may not work on PS2 at all), but you can try this command:
\\PoshCode.org\Modules\Install \\PoshCode.org\Modules\WASP.psd1
If you get timeouts (command not found) trying to execute off the WebDAV share, you can try the steps in kb2445570 or you can download the Install.ps1 scripts and the http://poshcode.org/Modules/WASP-2.0.0.6.psmx (which is a windows Package file -- you can actually just rename it to zip and then unzip and find the "WASP" module folder and install it manually instead of using the Install.ps1)

Anyway, I haven't uploaded the source to WASP 2 here because I'm still not happy with the command surface, it includes stuff like the horribly un-powershelly:

Invoke-Window.SetWindowVisualState -State Minimized

But you can probably work with it anyway, and presumably you'll be able to figure out how to min/max/resize/focus just by looking at the commands that are exported from the module.

You cannot send "Win" with the Send-Keys or Send-UIKeys, they're based on System.Windows.Forms.SendKeys, but the rest of it is documented there. Having said that, I'd argue there isn't anything you should need to automate with the Win key that you can't automate some other way ;-)

I've been meaning to migrate the Send-UIKeys to use InputSimulator but haven't gotten around to it. That one can definitely send the logo key, etc.


P.S.: There are existing "script compilers" for PowerShell (including as part of third-party editors/shells), including at least one which "encrypts" the scripts so it's harder to extract with reflection.

They basically just embed the script as a resource, and then use PowerShell's APIs to execute (so all you need is a modern Windows box that has PowerShell preinstalled), and you can double-click the exe. Frankly, I believe that's shortsighted, but never mind, as far as I know, they don't deal with compiling third-party binary modules into your resulting .exe and importing them as modules into the PowerShell runspace, but all of that is certainly possible with the PowerShell API, although I can't imagine a non-nefarious reason that would make doing so worthwhile over using an installer like the PoshCode module or, within a corporation, a simple UNC path where you store your modules...