torsdag 8 oktober 2009

CeRunAppAtEvent - Using CSharp

Yesterday we looked at how to use CeRunAppAtTime for executing applications at a specific date and time. CeRunAppAtTime has a sibling, CeRunAppAtEvent, that allows for executing applications at specific OS events. The events available to trigger are the following:
    public enum CeNotificationEvent
{
NOTIFICATION_EVENT_NONE
, NOTIFICATION_EVENT_TIME_CHANGE
, NOTIFICATION_EVENT_SYNC_END
, NOTIFICATION_EVENT_ON_AC_POWER
, NOTIFICATION_EVENT_OFF_AC_POWER
, NOTIFICATION_EVENT_NET_CONNECT
, NOTIFICATION_EVENT_NET_DISCONNECT
, NOTIFICATION_EVENT_DEVICE_CHANGE
, NOTIFICATION_EVENT_IR_DISCOVERED
, NOTIFICATION_EVENT_RS232_DETECTED
, NOTIFICATION_EVENT_RESTORE_END
, NOTIFICATION_EVENT_WAKEUP
, NOTIFICATION_EVENT_TZ_CHANGE
, NOTIFICATION_EVENT_MACHINE_NAME_CHANGE
, NOTIFICATION_EVENT_RNDIS_FN_DETECTED
, NOTIFICATION_EVENT_INTERNET_PROXY_CHANGE
, NOTIFICATION_EVENT_LAST = NOTIFICATION_EVENT_INTERNET_PROXY_CHANGE
};

Just as with CeRunAppAtTime, CeRunAppAtEvent resides in CoreDll.dll and its declaration are as follows:
        [DllImport("CoreDLL.dll", SetLastError = false, EntryPoint="CeRunAppAtEvent")]
public extern static bool RunAppAtEvent(string AppName, [MarshalAs(UnmanagedType.U4)]CeNotificationEvent WhichEvent);


To set an application for execution when the system time is changed you call CeRunAppAtEvent like this:
RunAppAtEvent(@"\windows\bubblebreaker.exe", Notify.CeNotificationEvent.NOTIFICATION_EVENT_TIME_CHANGE);

And you cancel the execution of an application like this:
RunAppAtEvent(@"\windows\bubblebreaker.exe", Notify.CeNotificationEvent.NOTIFICATION_EVENT_NONE);

That's it.. Tomorrow we'll look at CeSetUserNotification as well as CeHandleAppNotifications and on Monday I'll explain why you really shouldn't use any of these APIs.

Inga kommentarer:

Skicka en kommentar