Python Windows Service仅在调试模式下工作

时间:2018-07-27 01:34:13

标签: python windows wmi

我使用此函数在Windows上返回了进程列表,如果我在Python中运行它,它运行得很好。

我遇到的问题是当我使用pyinstaller将代码作为服务编译时。它一直运行到到达c = wmi.WMI()为止,并且服务在那里停止。

有人可以帮助我做一些避免这种情况的事情吗?

功能

import wmi

def getProcessList(so):    
    procList = []

    if 'win' in so:
        print('inside function list as windows')

        c = wmi.WMI()
        print('getting proccess list:')

        for process in c.Win32_Process():
            procList.append({'pid': process.ProcessId, 'p_name': process.Name})

    return procList

参考

  

http://timgolden.me.uk/python/wmi/cookbook.html

更新

尝试使用win32com库,而run.exe start面临相同的问题。但是,在调试模式下运行时,该服务就像一个超级按钮一样工作。

from win32com.client import GetObject

def getProcessList(so):    
    procList = []

    if 'win' in so:
        print('inside function list as windows')

        processes = WMI.InstancesOf('Win32_Process')
        print('amount of process: ' + str(len(processes)) + '.')

        for process in processes:
            procList.append({'pid': process.Properties_('ProcessId').Value, 'p_name': process.Properties_('Name').Value})

    return procList

0 个答案:

没有答案
相关问题