Protokolleintag beim Beenden von Windows
Verfasst: Montag 6. August 2007, 07:45
Hallo Pythonfreunde,
ich habe mir folgendes Script geschieben um den Start und das Beenden von Windows zu protokollieren. Leider bekomme ich den WM_ENDSESSION Event irendwie nicht mit. An was könnte das liegen.
Danke für eure Hilfe
alpha
ich habe mir folgendes Script geschieben um den Start und das Beenden von Windows zu protokollieren. Leider bekomme ich den WM_ENDSESSION Event irendwie nicht mit. An was könnte das liegen.
Code: Alles auswählen
# -*- coding: iso-8859-1 -*-
import time
import winsound
import thread
from Tkinter import *
def Startup():
savefile = "c:/work/zeiterfassung/proto.txt"
YYYY,MM,DD,hh,mm,ss,dw,dy,x = time.localtime()
try:
fz = open(savefile, "a")
fz.write("PC Startup: " + str(DD) + "." + str(MM) + "." + str(YYYY) + " " + str(hh) + ":" + str(mm) + ":" + str(ss) + "\n")
fz.close()
except:
print "Konnte Datei nicht öffnen!"
def gettime():
YYYY,MM,DD,hh,mm,ss,dw,dy,x = time.localtime()
# kommentar
if ss == int(0) and mm == int(0) and hh == int(12) and dw < 4:
winsound.PlaySound("c:\scripts\SPEECH\Pause.wav",0)
if ss == int(0) and mm == int(0) and hh == int(9):
winsound.PlaySound("c:\scripts\SPEECH\SpielUnterbrochen.WAV",0)
def Shutdown():
print "Shutdown"
savefile = "c:/work/zeiterfassung/proto.txt"
YYYY,MM,DD,hh,mm,ss,dw,dy,x = time.localtime()
fz = open(savefile, "a")
fz.write("PC Shutdown: " + str(DD) + "." + str(MM) + "." + str(YYYY) + " " + str(hh) + ":" + str(mm) + ":" + str(ss) + "\n")
fz.close()
sys.exit(0)
"""print "Konnte Datei nicht öffnen!"
sys.exit(0)
return -1"""
def Main(mf, lblTimeDate):
while 1:
YYYY,MM,DD,hh,mm,ss,dw,dy,x = time.localtime()
if ss <= 9:
ss = "0" + str(ss)
if mm <= 9:
mm = "0" + str(mm)
if hh <= 9:
hh = "0" + str(hh)
if DD <= 9:
DD = "0" + str(DD)
if MM <= 9:
MM = "0" + str(MM)
DateAndTime = str(DD) + "." + str(MM) + "." + str(YYYY) + " " + str(hh) + ":" + str(mm) + ":" + str(ss)
lblTimeDate["text"] = DateAndTime
gettime()
time.sleep(0.8)
Startup()
mf = Tk(className="MyTime2.0")
mf.protocol("WM_ENDSESSION", Shutdown)
mf.protocol("WM_QUERYENDSESSION", Shutdown)
mf.protocol("WM_DELETE_WINDOW", Shutdown)
mf.geometry('300x30+0+0')
#mf.overrideredirect(1) # fenster ohne aussen rum :-)
mf.attributes('-alpha', 0.5) # fenster transparent
#mf.attributes('-topmost', 1) # fenster immer im vordergrund
lblTimeDate = Label(mf, text = "", font = "courier 20 bold")
lblTimeDate.pack()
thread.start_new_thread(Main,(mf,lblTimeDate))
mf.mainloop()
Danke für eure Hilfe
alpha