Click here to Skip to main content
12,547,231 members (62,243 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked

Using CeSetUserNotification to start a program

, 30 Jan 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
A few days ago I got a message from a developer that was trying to use CeRunAppAtTime to schedule an application to start up.

A few days ago I got a message from a developer that was trying to use CeRunAppAtTime to schedule an application to start up. As I had mentioned in a previous post instead of using this function one should use CeSetUserNotification since on more recent devices CeRunAppAtTime is not as reliable (not to mention it is marked as deprecated in the MSDN documentation).

The developer asked me for an example of how to call the method from .Net so I put together an example for him. I am sharing the example below and plan to later update my article at on Automatically Starting a Windows Mobile Program with this same code.

public static extern IntPtr CeSetUserNotification(IntPtr hNotification, string application, 
                                                   SystemTime startTime,
                                                   UserNotification notification);

public static extern int FileTimeToSystemTime(ref long lpFileTime, SystemTime lpSystemTime);
public static extern int FileTimeToLocalFileTime(ref long lpFileTime, ref long lpLocalFileTime);

    public class UserNotification
        public int ActionFlags;
        public string DialogTitle;
        public string DialogText;
        public string SoundPath;
        public int MaxSoundPath;
        public IntPtr Reserved;

        public UserNotification()
            DialogTitle = String.Empty;
            DialogText = String.Empty;
            SoundPath = String.Empty;
            MaxSoundPath = 0;
            Reserved = IntPtr.Zero;
            ActionFlags = 0;

    public static void RunAppAtTime(string applicationEvent, DateTime startTime)
        long fileTimeUTC = startTime.ToFileTime();
        long fileTimeLocal = 0;
        UserNotification notification;
        notification = new UserNotification();
        notification.ActionFlags = 0;
        notification.Reserved = IntPtr.Zero;

        SystemTime systemStartTime = new SystemTime();
        FileTimeToLocalFileTime(ref fileTimeUTC, ref fileTimeLocal);
        FileTimeToSystemTime(ref fileTimeLocal, systemStartTime);
        CeSetUserNotification(IntPtr.Zero ,applicationEvent, systemStartTime, 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Joel Ivory Johnson
Software Developer Razorfish
United States United States
I attended Southern Polytechnic State University and earned a Bachelors of Science in Computer Science and later returned to earn a Masters of Science in Software Engineering.

For the past few years I've been providing solutions to clients using Microsoft technologies for web and Windows applications.

While most of my articles are centered around Windows Phone it is only one of the areas in which I work and one of my interests. I also have interest in mobile development on Android and iPhone. Professionally I work with several Microsoft technologies including SQL Server technologies, Silverlight/WPF, ASP.Net and others. My recreational development interest are centered around Artificial Inteligence especially in the area of machine vision.


You may also be interested in...


Comments and Discussions

QuestionKill the notification been set? Pin
HGolfer5-Feb-14 7:56
memberHGolfer5-Feb-14 7:56 
GeneralWake Pin
KentCampbell28-Apr-10 10:15
memberKentCampbell28-Apr-10 10:15 
AnswerRe: Wake Pin
Paul Heil22-Jun-11 3:34
memberPaul Heil22-Jun-11 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161018.1 | Last Updated 30 Jan 2010
Article Copyright 2010 by Joel Ivory Johnson
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid