0

I have written a python script that collect some WMI data from machine.

I want this script to run 24*7 and get the WMI data.

How can I get this script to execute 24/7, such as turning it into agent or service in Windows. I also need a loop that never ends in the program, or can it be done by just having the code re executed multiple times?

Thanks

Here the basic script.

import os
import time
import wmi

c = wmi.WMI()
def systeminfo1():
    for cpu in c.Win32_Processor():
        print('cpu_useper', cpu.LoadPercentage)
        
def systeminfo():
    for mem in c.Win32_PerfFormattedData_PerfOS_Memory():
        print('Memused_perc', mem.PercentCommittedBytesInUse)
       
while True:
    systeminfo()
    time.sleep(5)
    systeminfo1()
    time.sleep(30)
Roxx
  • 3,738
  • 20
  • 92
  • 155
  • 2
    I suggest you investigate [py2exe](http://www.py2exe.org/), this can be used to package your script as a Windows service. – Martin Evans Feb 08 '16 at 11:54
  • Why can you not have a bat file that runs based on the scheduler in windows? Wouldn't that be super simple? – Carlos Feb 08 '16 at 11:59
  • If i need to run this script on more than 1000 machines then i don't think this is a good idea – Roxx Feb 08 '16 at 12:01
  • 1
    I think this is what you are looking for http://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how – sorin Feb 08 '16 at 18:53
  • Possible duplicate of [Is it possible to run a Python script as a service in Windows? If possible, how?](https://stackoverflow.com/questions/32404/is-it-possible-to-run-a-python-script-as-a-service-in-windows-if-possible-how) – Mark Rotteveel Oct 26 '17 at 14:40

0 Answers0