在android应用程序中运行python脚本

时间:2022-08-06 20:21:45

I want to get list of installed software on remote computer.For that I want to use python script in my android application.Now,I have a python script which is getting the list of installed software on remote computer.But,I don't know how to make it supported in android.
For this, I found SL4A android Scripting here . So, I tried to run my python script in android device using SL4A.But,It's not working and giving me error because some packages like win32.client is missing.I don't know more about SL4A so I don't know how to convert my python script in Android supported form.So,anyone have any idea or code please suggest me.....

我想在远程计算机上获得已安装软件的列表。为此我想在我的android应用程序中使用python脚本。现在,我有一个python脚本,它在远程计算机上获取已安装软件的列表。但是,我不知道知道如何在android中支持它。为此,我在这里找到了SL4A android Scripting。所以,我尝试使用SL4A在Android设备上运行我的python脚本。但它不起作用并且给我错误,因为某些软件包如win32.client缺失。我不知道更多关于SL4A因此我不知道如何在Android支持的格式转换我的python脚本。所以,任何人有任何想法或代码请建议我.....

Also If anyone have another way to get installed software list from remote Pc then please suggest...
Below is my python script

另外如果有人有另一种方法从远程PC获得安装的软件列表,那么请建议......下面是我的python脚本

import wmi
from winreg import (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, OpenKey, EnumValue, QueryValueEx)

c = wmi.WMI(computer="PC02",user="admin",password="a@1",namespace="root/default").StdRegProv
result, names = c.EnumKey (hDefKey=HKEY_LOCAL_MACHINE, sSubKeyName=r"Software\Microsoft\Windows\CurrentVersion\Uninstall")

print('These subkeys are found under "HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"\n\n')

separator = "*" * 80
keyPath = r"Software\Microsoft\Windows\CurrentVersion\Uninstall"
count = 0

while count < len(names):

    try:      
        print(separator+'\n')

        path = keyPath + "\\" + names[count]
        key = OpenKey(HKEY_LOCAL_MACHINE, path, 0, KEY_ALL_ACCESS)
        temp = QueryValueEx(key, 'DisplayName')
        display = str(temp[0])
        print (" Name: "+display+'\n',"key:",names[count])

        count += 1
    except:
        print ("Key:",names[count])
        count += 1
        continue

5 个解决方案

#1


3  

Run the script on your remote computer, and expose the list of installed software on HTTP, a good way to write this simple web app is to use flask and its development server to serve the list of installed software, then write a python script which uses the native android web interface to fetch the list and display it.

在远程计算机上运行脚本,并在HTTP上公开已安装软件的列表,编写这个简单的Web应用程序的好方法是使用flask及其开发服务器来提供已安装软件的列表,然后编写一个使用的python脚本本机android web界面来获取列表并显示它。

#2


2  

You are having problems with missing libraries because you are importing windows specific ones. At any rate, this isn't the correct script to be running. This script seems to be for a computer, not an android phone.

您在删除库时遇到问题,因为您要导入特定于Windows的库。无论如何,这不是正确的脚本。这个脚本似乎适用于计算机,而不是Android手机。

#3


1  

You're trying to use a Python script that uses Windows Management Instrumentation (WMI), on a device that doesn't have that library.

您正在尝试在没有该库的设备上使用使用Windows Management Instrumentation(WMI)的Python脚本。

Sadly, WMI on Python requires the win32 library, which is only available on Windows. I don't think you're going to have much success on checking the installed programs on remote Windows computer from an Android device in this way.

遗憾的是,Python上的WMI需要win32库,该库仅在Windows上可用。我认为以这种方式从Android设备检查远程Windows计算机上安装的程序不会有太大成功。

#4


0  

Since WMI is based on WBEM, you may be able to use wbem to access it; you might want to try using pywbem, a pure python wbem library.

由于WMI基于WBEM,您可以使用wbem来访问它;你可能想尝试使用pywbem,一个纯python wbem库。

#5


0  

Running python scripts is now achievable in gradle system using Tasks

现在可以使用Tasks在gradle系统中运行python脚本

task pythonFile(type:Exec) {
workingDir 'src_path'
commandLine 'python', 'my_script.py'
} 

#1


3  

Run the script on your remote computer, and expose the list of installed software on HTTP, a good way to write this simple web app is to use flask and its development server to serve the list of installed software, then write a python script which uses the native android web interface to fetch the list and display it.

在远程计算机上运行脚本,并在HTTP上公开已安装软件的列表,编写这个简单的Web应用程序的好方法是使用flask及其开发服务器来提供已安装软件的列表,然后编写一个使用的python脚本本机android web界面来获取列表并显示它。

#2


2  

You are having problems with missing libraries because you are importing windows specific ones. At any rate, this isn't the correct script to be running. This script seems to be for a computer, not an android phone.

您在删除库时遇到问题,因为您要导入特定于Windows的库。无论如何,这不是正确的脚本。这个脚本似乎适用于计算机,而不是Android手机。

#3


1  

You're trying to use a Python script that uses Windows Management Instrumentation (WMI), on a device that doesn't have that library.

您正在尝试在没有该库的设备上使用使用Windows Management Instrumentation(WMI)的Python脚本。

Sadly, WMI on Python requires the win32 library, which is only available on Windows. I don't think you're going to have much success on checking the installed programs on remote Windows computer from an Android device in this way.

遗憾的是,Python上的WMI需要win32库,该库仅在Windows上可用。我认为以这种方式从Android设备检查远程Windows计算机上安装的程序不会有太大成功。

#4


0  

Since WMI is based on WBEM, you may be able to use wbem to access it; you might want to try using pywbem, a pure python wbem library.

由于WMI基于WBEM,您可以使用wbem来访问它;你可能想尝试使用pywbem,一个纯python wbem库。

#5


0  

Running python scripts is now achievable in gradle system using Tasks

现在可以使用Tasks在gradle系统中运行python脚本

task pythonFile(type:Exec) {
workingDir 'src_path'
commandLine 'python', 'my_script.py'
}