# Problem uninstalling Windows app from script

**URL:** <https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839>\
**Category:** Get Help\
**Tags:** windows\
**Created:** [October 20, 2023, 12:51pm UTC](https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839 "2023-10-20T12:51:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![km12345](https://avatars.discourse-cdn.com/v4/letter/k/e8c25b/32.png) [@km12345](https://forum.ansible.com/u/km12345)\
**Post date:** [October 20, 2023, 12:51pm UTC](https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839/1 "2023-10-20T12:51:35Z")

</div>

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](http://10.0.50.17/nuget)”  
state: absent

Thanks for help

---

<div class="post-metadata">

**Author:** ![bmbufalo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bmbufalo/32/295_2.png) [@bmbufalo](https://forum.ansible.com/u/bmbufalo)\
**Post date:** [October 20, 2023, 1:21pm UTC](https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839/2 "2023-10-20T13:21:31Z")

</div>

> [@km12345](#):
>
> ```auto
> name: Uninstall TeamViewer
> win_package:
> path: “C:\Program Files (x86)\TeamViewer\uninstall.exe”
> arguments: /S
> state: absent
> 
> ```

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](https://docs.ansible.com/ansible/latest/collections/ansible/windows/win_package_module.html) 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:

```yaml
- 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:

```powershell
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! 😃).

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.

---

<div class="post-metadata">

**Author:** ![km12345](https://avatars.discourse-cdn.com/v4/letter/k/e8c25b/32.png) [@km12345](https://forum.ansible.com/u/km12345)\
**Post date:** [October 23, 2023, 1:46pm UTC](https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839/3 "2023-10-23T13:46:41Z")

</div>

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](https://us1.discourse-cdn.com/ansible/original/2X/9/91d7fcb853986c87ec18ae20166dc13200f0947d.png)

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

---

<div class="post-metadata">

**Author:** ![bmbufalo](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bmbufalo/32/295_2.png) [@bmbufalo](https://forum.ansible.com/u/bmbufalo)\
**Post date:** [October 23, 2023, 2:35pm UTC](https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839/4 "2023-10-23T14:35:12Z")

</div>

After looking at the [choco docs for teamviewer.host](https://community.chocolatey.org/packages/teamviewer.host#files), it seems like the install uses the name as the product\_id:

```plaintext
$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:

```plaintext
- 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.

---

<div class="post-metadata">

**Author:** ![km12345](https://avatars.discourse-cdn.com/v4/letter/k/e8c25b/32.png) [@km12345](https://forum.ansible.com/u/km12345)\
**Post date:** [October 24, 2023, 7:05am UTC](https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839/5 "2023-10-24T07:05:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![astrakid](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/astrakid/32/1789_2.png) [@astrakid](https://forum.ansible.com/u/astrakid)\
**Post date:** [December 14, 2023, 7:41am UTC](https://forum.ansible.com/t/problem-uninstalling-windows-app-from-script/1839/6 "2023-12-14T07:41:05Z")

</div>

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?
