1

I was looking for some assistance with some code I've been working on, which has been designed to check your current OS architecture, and to run the relevant uninstaller for TeamViewer depending on the values returned...

Please forgive my basic Powershell knowledge, but I've knocked together the below, and I'm getting the following error: Start-Process : This command cannot be run due to the error: The system cannot find the file specified.

It's almost like if it can't find the initial uninstaller, then the code stops.

if ((gwmi win32_operatingsystem | select osarchitecture).osarchitecture -eq "64-bit")
{
    #64 bit TeamViewer Uninstall
    Start-Process -FilePath "C:\Program Files\TeamViewer\uninstall.exe"
        $StartTVUninstaller = New-Object -ComObject wscript.shell;
        Sleep 2
        $StartTVUninstaller.SendKeys('~') 
        Sleep 10
        $StartTVUninstaller.SendKeys('%{F4}') 
        sleep 2
        Stop-Process -name Un_A 
}
else
{
    #32 bit TeamViewer Uninstall
    Start-Process -Filepath "-file C:\Program Files (x86)\TeamViewer\uninstall.exe"
        $StartTVUninstaller_32 = New-Object -ComObject wscript.shell;
        Sleep 2
        $StartTVUninstaller_32.SendKeys('~')  
        Sleep 10
        $StartTVUninstaller_32.SendKeys('%{F4}')
        sleep 2
        Stop-Process -name Un_A
}

Ignore the 'SendKeys' elements for now, this is more for when the Uninstaller has launched and will attempt to make the uninstallation process seemless.

The reason this is being done this way, is due to TeamViewer being deployed en masse using the executable, and not a custom packaged MSI.

Hopefully someone can point me in the right direction.

zett42
  • 25,437
  • 3
  • 35
  • 72
CHulala
  • 11
  • 1
  • You should type `-eq "64 bits"` and not `-eq "64-bit"` – Christophe Jul 28 '22 at 08:10
  • Hey @Christophe, thanks for the reply. I've just added that in now - it's still failing at Start-Process element, but appreciate the help here. – CHulala Jul 28 '22 at 08:25
  • 1
    Take off the `-file` at `Start-Process -Filepath "-file C:\...` – Christophe Jul 28 '22 at 08:53
  • 1
    did you try to add `-ArgumentList "/S"` at your `Start-Process` to run uninstall silently ? – Christophe Jul 28 '22 at 10:01
  • No I hadn't, but I will do @Christophe! Still getting the 'Start-Process : This command cannot be run due to the error: The system cannot find the file specified.' message - I'm continuing to attempt to break this down – CHulala Jul 28 '22 at 11:15
  • Use `if (((Get-WmiObject win32_operatingsystem | Select-Object osarchitecture).osarchitecture -replace '\D+') -eq "64")`. The string you get in property `OsArchitecture` is **Localized**, so for some it is `64-bits`, for others `64 bit`. By replacing all non-digit characters, you can simply test for "64" – Theo Jul 28 '22 at 11:19

0 Answers0