c# - .Net service receive SERVICE_CONTROL_TIMECHANGE -
i'm writing windows service using vb.net , built-in system.serviceprocess.servicebase class uses onsessionchange function track when users log in , out. can determine how time each user spends on computer.
i detect when system time changes, not affect accuracy of data collected, , looks microsoft has added message purpose: service_control_timechange, of windows 7.
however, built-in servicebase class not support message, , doesn't seem extensible can add full support message. note can receive message (stripped of it's parameter) using code:
public class timemanager public sub new() initializecomponent() 'modify base class' field... enabletimechange() end sub private sub enabletimechange() try dim acceptedcommands reflection.fieldinfo = me.gettype().basetype.getfield("acceptedcommands", reflection.bindingflags.nonpublic or reflection.bindingflags.instance or reflection.bindingflags.ignorecase) if acceptedcommands isnot nothing dim value integer = acceptedcommands.getvalue(me) value = value or &h200 acceptedcommands.setvalue(me, value) else me.eventlog.writeentry("reflection not find 'acceptedcommands'!", eventlogentrytype.warning) end if catch ex exception me.eventlog.writeentry(ex.tostring(), eventlogentrytype.warning) end try end sub protected overrides sub oncustomcommand(command integer) select case command case 16 'service_control_timechange me.eventlog.writeentry("time changed!", eventlogentrytype.information) end select end sub end class i need parameter though, because says old time (before time change). how should go this? there way without re-implementing servicebase myself?
Comments
Post a Comment