0

I have a simple powershell command to open a web application, and then input the quick-keys required to close it:

#Open Application in Browser
Add-Type –AssemblyName System.Windows.Forms
$ie = New-Object -com "InternetExplorer.Application"
$ie.Navigate("http://UrlPath")
$ie.visible = $true

#Quick key to exit application
sleep 15
[System.Windows.Forms.SendKeys]::SendWait("%{X}")

This code executes with no issue when I use powershell ISE outside Jenkins. But When I try to execute the code using the Powershell plugin, or using a batch file command within Jenkins to call the .ps1 file, it will always return the following errors.

Screenshot of errors returned by Jenkins

I'm using a virtual machine at work so at first I thought that was the issue. But I get the same results when using my home PC too. Any suggestions? I think the problem is permission based I'm not sure where to look to solve it.

The Powershell ISE I use outside jenkins is 32-bit, version 2.0

LeChuck
  • 71
  • 9
  • Is Jenkins running as a service? – Poorkenny Sep 13 '16 at 15:15
  • Yes. A windows service – LeChuck Sep 13 '16 at 15:17
  • 1
    Have you tried configuring DCOM to allow the user running the Jenkins service to create a COM Object of IE ? (How to do is explained in the first response of http://stackoverflow.com/questions/17750928/how-to-uniquely-identify-an-internet-explorer-window-running-in-session-0) – Gzeh Niert Sep 13 '16 at 15:19
  • @GzehNiert's answer makes more sense than what I was about to suggest. Give it a try and let us know :) – Poorkenny Sep 13 '16 at 15:23
  • Managed to find DCOM and followed these instruction but errors still persist on Jenkins. I don't think this would solve my Sendkeys errors anyway. They are probably both related to a common issue. I just wish I knew what it was. – LeChuck Sep 13 '16 at 15:52
  • I don't think you can use SendKeys in non-interactive mode, because sending a key is an interaction. – Gzeh Niert Sep 13 '16 at 15:56
  • Are you sure? I think I can find a work around with that anyway, but I definitely need to use the COM objects. – LeChuck Sep 13 '16 at 16:17

0 Answers0