程序执行期间可以在python 32位和python 64位之间切换吗?

时间:2018-10-01 19:03:13

标签: python python-2.7 pywinauto

要求:

从“添加”中删除应用程序。此代码需要python 64位。我要从中执行卸载操作的python脚本需要32位python,因为有些DLL是使用32位python编译的。

反正我能做到吗?是否有可能在python的两种体系结构之间切换?我想知道我能否将卸载脚本保留为单独的python模块,并以某种方式强制其使用python 64位运行。可能吗?

Python专家请帮忙。

Python版本:2.7.12

结构:

My python application (require 32 bit python)

    Uninstall() (require 64 bit python)

My script continues (require 32 bit python)

卸载代码()

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:
    print "hello"
    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()

1 个答案:

答案 0 :(得分:0)

您考虑过使用两种不同的方法吗?

  1. 为您的应用程序启动一个32位python进程。
  2. 您的应用程序请求执行单独的64位python进程以运行您的selectedItem函数。
  3. 您的应用程序等待,直到64位python进程终止。
  4. 您的应用程序继续运行。