Problem uninstalling Windows app from script

I’m hosting ansible host on Unbuntu and want to uninstall Teamviewer on windows client with openssh. I have tested that “C:\Program Files (x86)\TeamViewer\uninstall.exe” /S which im running locally from cmd works but Im struggling to run this from ansible in any way (win_command, win_shell, raw etc.) Task is passing but nothing happens. Currently after many tries I have this in c:\temp\command.bat and for example task

  • name: Execute command.bat
    win_command: c:\temp\command.bat
    register: result

is giving me that but app is not uninstalled.

changed: [DESKTOP-TTV1HDR.local] => {
“changed”: true,
“cmd”: “c:\temp\command.bat”,
“delta”: “0:00:00.234340”,
“end”: “2023-10-20 12:41:41.207614”,
“invocation”: {
“module_args”: {
“_raw_params”: “c:\temp\command.bat”,
“argv”: null,
“chdir”: null,
“cmd”: null,
“creates”: null,
“output_encoding_override”: null,
“removes”: null,
“stdin”: null
}
},
“rc”: 0,
“start”: “2023-10-20 12:41:40.973274”,
“stderr”: “”,
“stderr_lines”: ,
“stdout”: “\r\nadmin@DESKTOP-TTV1HDR C:\Users\Admin>"C:\Program Files (x86)\TeamViewer\uninstall.exe" /S \r\n”,
“stdout_lines”: [
“”,
"admin@DESKTOP-TTV1HDR C:\Users\Admin>"C:\Program Files (x86)\TeamViewer\uninstall.exe" /S "
]
}

Below are tasks which I already tested:

  • name: Uninstall TeamViewer
    win_package:
    path: “C:\Program Files (x86)\TeamViewer\uninstall.exe”
    arguments: /S
    state: absent
  • name: Run uninstall command
    ansible.windows.win_command: ‘“C:\Program Files (x86)\TeamViewer\uninstall.exe” /S’
    register: result
  • name: Choco Uninstall TV Host
    win_chocolatey:
    name: teamviewer.host
    version: ‘15.46.7.0’
    source: “http://10.0.50.17/nuget
    state: absent

Thanks for help

For removing software, I’ve found it best to use win_package as you tried in your testing. Pulling from the examples in the documentation for that module, you will need to get the product code for the app before you try to remove it but once you do, you should be able to easily send the following:

- name: Uninstall Remote Desktop Connection Manager
  ansible.windows.win_package:
    product_id: '{0240359E-6A4C-4884-9E94-B397A02D893C}'
    state: absent

Note: You do not need to include a path (this is only for installation tasks, usually) for removing if you have the product_id. To find the product_id, run this from PowerShell on a machine that has TeamViewer installed:

Get-WMIObject win32_product | Format-Table -AutoSize

And notate the output for your app and its IdentifyingNumber to use for Ansible’s product_id. It looks like your SSH setup is working fine based on the output you’ve provided (great news! :smiley:).

Lastly, managing packages on Windows is a pain, but reading the win_package for all the ins and outs of how to use it will usually result in what you need. And you ill get the best results using this rather than calling a script, usually.

1 Like

Thank you for your reply.

I tried that approach but im not able to get product id of Teamviewer_Host in any way.
I’m installing it by choco install teamviewer_host. Even if I uninstall it with choco it removes from choco installed apps but the program stays unotuched. The only way that is the cmd line i mentioned in my previous post.
image

I even tried to remove it with plink.exe which should work like manual ssh but still without success.

After looking at the choco docs for teamviewer.host, it seems like the install uses the name as the product_id:

$ErrorActionPreference = 'Stop'

$packageName = 'teamviewer.host'
$url32       = 'https://download.teamviewer.com/download/version_15x/TeamViewer_Host_Setup.exe'
$checksum32  = '05ebac8a9a109d120d351e88deeba48677cb4115527177a55b7ec0e7a7953dd8'

$packageArgs = @{
  packageName            = $packageName
  fileType               = 'EXE'
  url                    = $url32
  checksum               = $checksum32
  checksumType           = 'sha256'
  silentArgs             = '/S'
  validExitCodes         = @(0)
  registryUninstallerKey = $packageName
}
Install-ChocolateyPackage @packageArgs

So substituting the name should get you what you need, something like:

- name: Uninstall TeamViewer
  win_package:
    product_id: teamviewer.host
    arguments: /S
    state: absent

If not, I would go to the source machine and remove it manually with as much logging and verbosity turned on to see what options or issues pop up on the one system to get additional clues for what is stopping this from working.

1 Like

Thank you very much for your reply.

It passed like that but app remains untouched.

ok: [DESKTOP-TTV1HDR.local] => {
“changed”: false,
“invocation”: {
“module_args”: {
“arguments”: “/S”,
“chdir”: null,
“client_cert”: null,
“client_cert_password”: null,
“creates_path”: null,
“creates_service”: null,
“creates_version”: null,
“expected_return_code”: [
0,
3010
],
“follow_redirects”: “safe”,
“force_basic_auth”: false,
“headers”: null,
“http_agent”: “ansible-httpget”,
“log_path”: null,
“maximum_redirection”: 50,
“path”: null,
“product_id”: “teamviewer.host”,
“provider”: “auto”,
“proxy_password”: null,
“proxy_url”: null,
“proxy_use_default_credential”: false,
“proxy_username”: null,
“state”: “absent”,
“url_method”: null,
“url_password”: null,
“url_timeout”: 30,
“url_username”: null,
“use_default_credential”: false,
“use_proxy”: true,
“validate_certs”: true,
“wait_for_children”: false
}
},
“rc”: 0,
“reboot_required”: false
}

The only way that actually works for me is this command
“C:\Program Files (x86)\TeamViewer\uninstall.exe” /S

but im unable to pass it properly from ansible. When I log in with ssh to this client and pass it manualy it works. Is there anyway to automate it from ansible?

Its not a hard issue to reproduce. Just “choco install teamviewer.host” and you are unable to uninstall it with ansible.

Thank you again for your engagement

i have the same issue, with manually installed apps. i think it is usually when installation was done with an executable (not msi).
did you find any workaround yet?