I want to prevent some process from running. The code is in the
following. I encounter some unexpected troubles.
Probelm1: This program cannot terminate "scrcons.ex e" and
"FNPLicensingSe rvice.exe",whic h are system processes.
Problem2:After a while, this program will abort by error
File "C:\Python25\li b\wmi.py", line 397, in __call__
handle_com_erro r (error_info)
File "C:\Python25\li b\wmi.py", line 190, in handle_com_erro r raise
x_wmi, "\n".join (exception_stri ng)
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xb7 in position
14: ordinal not in range(128)
----------------------------------------------------
code----------------------------------------------------------------------------------
# -*- coding:utf-8 -*-
import pythoncom
import wmi
import threading
import time
from xml.dom.minidom import parse, parseString
class Info (threading.Thre ad):
def __init__ (self):
threading.Threa d.__init__ (self)
def run (self):
print 'In Another Thread...'
pythoncom.CoIni tialize ()
dom1 = parse('processT erminateList.xm l')
config_element = dom1.getElement sByTagName("pro cessTerminateLi st")
[0]
servers = config_element. getElementsByTa gName("processN ame")
try:
c = wmi.WMI ()
for process in c.Win32_Process ():
for server in servers:
if process.name == getText(server. childNodes):
process.Termina te()
print process.name
process_watcher = c.Win32_Process .watch_for("cre ation")
while True:
new_process = process_watcher ()
name = new_process.Cap tion
print name
for server in servers:
if name == getText(server. childNodes):
new_process.Ter minate()
finally:
pythoncom.CoUni nitialize ()
def getText(nodelis t):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
if __name__ == '__main__':
Info().start()
------------------------------------------------------
processTerminat eList.xml-----------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<processTermina teList>
<processName>sc rcons.exe</processName>
<processName>TX Platform.exe</processName>
<processName>md m.exe</processName>
<processName>FN PLicensingServi ce.exe</processName>
<processName>no tepad.exe</processName>
<processName>ue dit32.exe</processName>
</processTerminat eList>
following. I encounter some unexpected troubles.
Probelm1: This program cannot terminate "scrcons.ex e" and
"FNPLicensingSe rvice.exe",whic h are system processes.
Problem2:After a while, this program will abort by error
File "C:\Python25\li b\wmi.py", line 397, in __call__
handle_com_erro r (error_info)
File "C:\Python25\li b\wmi.py", line 190, in handle_com_erro r raise
x_wmi, "\n".join (exception_stri ng)
UnicodeDecodeEr ror: 'ascii' codec can't decode byte 0xb7 in position
14: ordinal not in range(128)
----------------------------------------------------
code----------------------------------------------------------------------------------
# -*- coding:utf-8 -*-
import pythoncom
import wmi
import threading
import time
from xml.dom.minidom import parse, parseString
class Info (threading.Thre ad):
def __init__ (self):
threading.Threa d.__init__ (self)
def run (self):
print 'In Another Thread...'
pythoncom.CoIni tialize ()
dom1 = parse('processT erminateList.xm l')
config_element = dom1.getElement sByTagName("pro cessTerminateLi st")
[0]
servers = config_element. getElementsByTa gName("processN ame")
try:
c = wmi.WMI ()
for process in c.Win32_Process ():
for server in servers:
if process.name == getText(server. childNodes):
process.Termina te()
print process.name
process_watcher = c.Win32_Process .watch_for("cre ation")
while True:
new_process = process_watcher ()
name = new_process.Cap tion
print name
for server in servers:
if name == getText(server. childNodes):
new_process.Ter minate()
finally:
pythoncom.CoUni nitialize ()
def getText(nodelis t):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
if __name__ == '__main__':
Info().start()
------------------------------------------------------
processTerminat eList.xml-----------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<processTermina teList>
<processName>sc rcons.exe</processName>
<processName>TX Platform.exe</processName>
<processName>md m.exe</processName>
<processName>FN PLicensingServi ce.exe</processName>
<processName>no tepad.exe</processName>
<processName>ue dit32.exe</processName>
</processTerminat eList>
Comment