# launch executable on remote node

**URL:** <https://forum.ansible.com/t/launch-executable-on-remote-node/21410>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [May 11, 2016, 3:01pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410 "2016-05-11T15:01:52Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [May 11, 2016, 3:01pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/1 "2016-05-11T15:01:52Z")

</div>

Management Node:  
CentOs 7.1Ansible 2.1  
Remote Node:  
Windows 7  
Powershell 3.0

How do I launch an executable on a remote node running Windows 7? As I understand win\_scheduled\_task only works with Windows Server 2012 and win\_nssm is only for startup services. Is there any other way do do this? If not, is there any way to access the Invoke-Command option of Powershell? I suppose a module could be written to do that but I’m new to python and doubt I could pull it off.

Thanks,

Jonathan

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [May 11, 2016, 5:35pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/2 "2016-05-11T17:35:41Z")

</div>

You can use the raw module to run console applications. Things that start a gui may not start due to the lack of an interactive user.

- name: import a registry file  
raw: “reg.exe IMPORT C:\settings.reg”

(by the way, don’t the above, use win\_regedit or win\_regmerge instead - just an example of running an .exe which is available on the PATH)

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [June 24, 2016, 1:11pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/3 "2016-06-24T13:11:14Z")

</div>

Is it possible to launch a web service that would in turn launch a gui executable?

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 24, 2016, 2:11pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/4 "2016-06-24T14:11:42Z")

</div>

I wouldn’t know for sure but it would be unusual. Usually web services have some kind of client which can be launched independently from a web service.

When you are doing things via winrm, its my understanding that there is no interactive user session, meaning there’s no gui associated with the commands being run. Not a problem for command line programs that communicate via stdout and stderr, but if you only have a gui then that’s an issue.

What are you trying to achieve?

You could, for example use net send to send a pop up message to any logged on users who do have interactive sessions (and guis to look at).

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [June 24, 2016, 2:16pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/5 "2016-06-24T14:16:38Z")

</div>

With each software upgrade I need to change several parameters in the gui. I have a console ap that can do this by sending tcp/ip commands to the gui. But in order for this to happen the gui must be opened after the new version has been installed.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [June 24, 2016, 2:17pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/6 "2016-06-24T14:17:52Z")

</div>

With each software upgrade I need to change several parameters in the gui. I have a console ap that can do this by sending tcp/ip commands to the gui. But in order for this to happen the gui must be opened after the new version has been installed.

![](https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif)

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [June 24, 2016, 2:32pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/7 "2016-06-24T14:32:09Z")

</div>

Hmm. It sounds like the gui app could do with being split up into a windows service with a separate client app for the gui interface.

I have encountered older windows apps which run as services but also present a GUI. For security reasons Microsoft have discouraged this for years now but I put a bit in my talk about working with such things at Ansiblefest London earlier this year. Slides are here: [http://www.slideshare.net/jhawkesworth/ansible-20-windows-and-no-powershell-this-year-i-promise-ansiblefest-london-2016](http://www.slideshare.net/jhawkesworth/ansible-20-windows-and-no-powershell-this-year-i-promise-ansiblefest-london-2016) and audio here [https://www.ansible.com/ansible-2-windows](https://www.ansible.com/ansible-2-windows)

The above won’t help if the app isn’t a service though - I think a bit of re-engineering might be needed - unless anyone else has some suggestions?

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [July 7, 2016, 6:48pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/8 "2016-07-07T18:48:52Z")

</div>

I have tried starting a new process from inside a .net console application called by ansible but it didn’t work. That process should have it’s own thread right? The process shows up momentarily on the Task Manager and then disappears. Alternatively I could reboot if there was some way to get through the Windows login process after rebooting. That would work as well.

---

<div class="post-metadata">

**Author:** ![Matt\_Davis](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@Matt\_Davis](https://forum.ansible.com/u/Matt_Davis)\
**Post date:** [July 7, 2016, 9:29pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/9 "2016-07-07T21:29:58Z")

</div>

You have to do some extra semi-complex magic when launching the process to break out of the winrm “jail”- otherwise anything you start will be nuked when your winrm session ends (by WinRM design, not Ansible’s). I’m building said magic into Ansible for 2.2 to support async tasks on Windows (among other things), and I’ll probably expose it on win\_shell/win\_command as well.

Not sure what you mean by “get through the Windows login process”, but have you looked at [win\_reboot](https://docs.ansible.com/ansible/win_reboot_module.html)?

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [July 8, 2016, 4:36pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/10 "2016-07-08T16:36:59Z")

</div>

The program I’m trying to launch starts up automatically after the user logs-in which could possibly be part of a solution for me. But I can’t depend on any user doing that for me so I would have to automate the login and I don’t see how win\_reboot can do that.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [July 11, 2016, 10:02am UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/11 "2016-07-11T10:02:06Z")

</div>

This script can set up auto logon for a user.  
[http://andyarismendi.blogspot.co.uk/2011/10/powershell-set-secureautologon.html](http://andyarismendi.blogspot.co.uk/2011/10/powershell-set-secureautologon.html)  
I have a role that runs this script and then calls win\_reboot to make the autologon happen.

Hope this helps,

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [July 11, 2016, 5:07pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/12 "2016-07-11T17:07:56Z")

</div>

Is your role on Ansible Galaxy? I searched for your name but came up with nothing. Do you use another name for your Galaxy contributions or where can I find the role you mentioned?

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [July 11, 2016, 5:33pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/13 "2016-07-11T17:33:50Z")

</div>

I tried converting my password to a secureString by using “ConvertTo-SecureString” commandlet of powershell like this.

- name Convert password to secure string  
raw: ConvertTo-SecureString “password” -AsPlainTest -Force  
register: result
- set\_fact: ssPassword={{result.stdout\_lines.0}}
- name Setup Auto Reboot  
script: Set-SecureAutoLogon.ps1 “{{userName}}” “{{ssPassword}}” “acme” “1” “true”

Then when I run it I get “Cannot process argument transformation non parameter “Password” Cannot convert the System.SecuritySecureString value of type System.String to type System.Security.SecureString”

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [July 12, 2016, 8:17am UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/14 "2016-07-12T08:17:41Z")

</div>

Hi,

Sorry role not shared anywhere right now. Keep meaning to put stuff on galaxy but haven’t found the time.

My apologies, looking at the code I’d forgotten that I’d tweaked the powershell script so I could pass in plaintext password. I doubt a SecureString would be serializable.

I think the only bit I changed was at the start of the process section. Instead of this

`process` `{`

`try` `{` `$ErrorActionPreference` `= `"Stop"` `  
`$decryptedPass` `= ``[Runtime.InteropServices.Marshal]``::PtrToStringAuto(` `[Runtime.InteropServices.Marshal]`::SecureStringToBSTR(`$Password``)` ```)`

I have this

`process` `{`

`try` `{` `$ErrorActionPreference` `= `"Stop"` `  
`$secPass = ConvertTo-SecureString -String $Password -AsPlainText -Force `

`$decryptedPass` `= ``[Runtime.InteropServices.Marshal]``::PtrToStringAuto(` `# [Runtime.InteropServices.Marshal]`::SecureStringToBSTR(`$Password``)`

```[Runtime.InteropServices.Marshal]`::SecureStringToBSTR(`$secPass``)`

```)`

Hope that helps,

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [July 13, 2016, 2:43pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/15 "2016-07-13T14:43:27Z")

</div>

I tried this and it worked fine but now my ansible profile is all messed up and many other tasks in my playbook are failing. My USERPROFILE is supposed to be C:\Users\ansibleAdmin but now it shows up as C:\Users\ansibleAdmin.DOMAIN or sometimes C:\Users\Temp.

---

<div class="post-metadata">

**Author:** ![j.r.hawkesworth](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@j.r.hawkesworth](https://forum.ansible.com/u/j.r.hawkesworth)\
**Post date:** [July 13, 2016, 3:24pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/16 "2016-07-13T15:24:30Z")

</div>

Sorry to hear this, hope you can go back to a snapshot or similar?

Can’t really think why it would be different.

I run the script like this:

`

- name: set auto logon  
script: “setSecureAutoLogon.ps1 -Username {{ automation\_user }} -Domain {{ windows\_domain\_name }} -Password {{ automation\_password }}”  
`

Jon

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [July 15, 2016, 8:21pm UTC](https://forum.ansible.com/t/launch-executable-on-remote-node/21410/17 "2016-07-15T20:21:41Z")

</div>

I tried a simpler powershell script and it seems to work fine.

Param(  
[string]$DefaultDomainname,  
[String]$DefaultUsername,  
[String]$DefaultPassword  
)

Begin  
{  
#Registry path declaration  
$RegPath = “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon”  
}

Process  
{

try  
{  
#setting registry values  
Set-ItemProperty $RegPath “AutoAdminLogon” -Value “1” -type String  
Set-ItemProperty $RegPath “DefaultDomainName” -Value $DefaultDomainname -type string  
Set-ItemProperty $RegPath “DefaultUsername” -Value “$DefaultUsername” -type String  
Set-ItemProperty $RegPath “DefaultPassword” -Value “$DefaultPassword” -type String  
}

catch  
{

Write-Output “An error had occured $Error”

}  
}

End  
{

#End

}
