Running a Windows .exe from Program Files

886 views
Skip to first unread message

Dimitri Yioulos

unread,
Feb 1, 2017, 9:18:40 AM2/1/17
to Ansible Project
Hi, all.

Another probably simple question that I need help with:

I need to run a program utility on several machines, as follows:

C:\Program Files\Kaspersky Lab\Network Agent\klmover.exe -address 172.16.1.1

I've tried running it using the raw command raw: c:\windows\system32\cmd.exe /C "C:\Program Files\Kaspersky Lab\Network Agent\klmover.exe -address 172.16.1.1"

I've tried several combinations of quotes around the command, and changing slashes/backslashes, but am not able to find a means to keep Ansible from complaining e.g. ""'C:\\Program' is not recognized as an internal or external command".  I think it has more to do with the spaces in the path.  Anyway, I would appreciate your help.

Many thanks.

Dimitri

J Hawkesworth

unread,
Feb 3, 2017, 12:35:29 AM2/3/17
to Ansible Project
Hi,

When using double quotes around windows paths, you usually have to use 2 backslashes for the path separator, so something like the following might work, although I think it might try and look for a program called 'klmover.exe -address 172.16.1.1' (instead of treating the -address 172.16.1.1 as arguments for the klmover.exe)


raw: c:\windows\system32\cmd.exe /C "C:\\Program Files\\Kaspersky Lab\\Network Agent\\klmover.exe -address 172.16.1.1"

You might not need to run via the cmd.exe though so perhaps try:

raw: "C:\\Program Files\\Kaspersky Lab\\Network Agent\\klmover.exe" -address 171.16.1.1

However, if you are using ansible 2.2 use win_command (or win_shell) modules instead of 'raw'. Try something like this (which I think is easier to read than the others above).

win_command
: klmover -address 172.16.1.1
args
:
  chdir
: C:\Program Files\Kaspersky Lab\Network Agent\

Hope this helps,

Jon

Dimitri Yioulos

unread,
Feb 3, 2017, 1:52:17 PM2/3/17
to Ansible Project
Hi, Jon.

The path to the executable is actually C:\Program Files (x86)\Kaspersky Lab\NetworkAgent,  My bad typing.

Since I am using version 2.2, I've tried win_command, and get the following error:

fatal: [machine10]: FAILED! => {"changed": false, "cmd": "klmover -address 192.168.192.18", "failed": true, "msg": "The system cannot find the file specified", "rc": 2}

The file klmover.exe IS in the specified directory.  The command does have to be "Run as Administrator", so I added become_user: Administrator, but that didn't help.

J Hawkesworth

unread,
Feb 5, 2017, 3:30:17 AM2/5/17
to Ansible Project
Unfortunately become is not yet supported for windows hosts. I know there is work happening on this.

Would it be possible to switch things around and connect as Administrator, or a user with local admin permissions?

Jon

Reply all
Reply to author
Forward
0 new messages