从程序和function中自动卸载

我正在尝试使用Python自动化从Windows 7和Windows 8.1中卸载一些应用程序。 Windows命令行也将工作。

程序显示在控制面板的“程序和function”列表中。 点击它们并select卸载将卸载它们没有问题。 通过点击“程序和function”菜单手动卸载可以正常工作。

这些程序是使用EXE文件而不是MSI文件安装的。

我到目前为止所尝试的:

1)

wmic product get name 

使用命令“wmic product get name”显示仅在“程序和function”页面上显示的一些程序的列表。 我想卸载的程序没有列出。

2)

 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall 

程序不会出现在上面的registry位置

3)

“使用pywinauto直接打开和操作程序和function窗口”。

pywinauto模块(或任何其他可以find并操纵窗口和button的手柄)可以打开并获取“程序和function”窗口,但操作失败。 特别是在search框中input文本失败,所以不能select卸载的程序。

4)

“使用该程序附带的卸载msi”。

没有一个。

5)

“再次运行安装程序可执行文件。”

这只是更新软件,而不是删除它。

我用pywinauto 0.5.2写了一个卸载的7-Zip示例。 它在Windows 7和Windows 8.1上对我都很稳定。 我相信这可能对别人有用。

当然这只是一个演示例子,因为7-Zip可以简单地通过“wmic”命令来卸载,并带有相应的参数。

 from __future__ import print_function import pywinauto pywinauto.Application().Start(r'explorer.exe') explorer = pywinauto.Application().Connect(path='explorer.exe') # Go to "Control Panel -> Programs and Features" NewWindow = explorer.Window_(top_level_only=True, active_only=True, class_name='CabinetWClass') try: NewWindow.AddressBandRoot.ClickInput() NewWindow.TypeKeys(r'Control Panel\Programs\Programs and Features{ENTER}', with_spaces=True, set_foreground=False) ProgramsAndFeatures = explorer.Window_(top_level_only=True, active_only=True, title='Programs and Features', class_name='CabinetWClass') # Wait while list of programs is loading explorer.WaitCPUUsageLower(threshold=5) item_7z = ProgramsAndFeatures.FolderView.GetItem('7-Zip 9.20 (x64 edition)') item_7z.EnsureVisible() item_7z.ClickInput(button='right', where='icon') explorer.PopupMenu.MenuItem('Uninstall').Click() Confirmation = explorer.Window_(title='Programs and Features', class_name='#32770', active_only=True) if Confirmation.Exists(): Confirmation.Yes.ClickInput() Confirmation.WaitNot('visible') WindowsInstaller = explorer.Window_(title='Windows Installer', class_name='#32770', active_only=True) if WindowsInstaller.Exists(): WindowsInstaller.WaitNot('visible', timeout=20) SevenZipInstaller = explorer.Window_(title='7-Zip 9.20 (x64 edition)', class_name='#32770', active_only=True) if SevenZipInstaller.Exists(): SevenZipInstaller.WaitNot('visible', timeout=20) if '7-Zip 9.20 (x64 edition)' not in ProgramsAndFeatures.FolderView.Texts(): print('OK') finally: NewWindow.Close()