Пример #1
0
        ///// <summary>
        ///// Unregister an application given the path to the executable or the token that was provided
        ///// </summary>
        ///// <param name="applicationOrToken">The path to the application executable or the token, whichever was provided.</param>
        //public static void UnscheduleApplicationLaunch(string applicationOrToken)
        //{
        //    IntPtr handle = FindApplicationNotification(applicationOrToken);
        //    while (handle != IntPtr.Zero)
        //    {
        //        CeClearUserNotification(handle);
        //        handle = FindApplicationNotification(applicationOrToken);
        //    }

        //    //bool bret = UnscheduleCeRunAppAtTime(applicationOrToken, IntPtr.Zero);

        //    //int ret = ConnMgrUnregisterScheduledConnection(GetTokenFromApplication(applicationOrToken));
        //}

        private static void CeSetUserNotificationEx(string application, string arguments, DateTime start)
        {
            //UnscheduleApplicationLaunch(application);

            IntPtr appBuff  = Marshal.StringToBSTR(application);
            IntPtr argsBuff = Marshal.StringToBSTR(arguments);

            var trigger = new UserNotificationTrigger
            {
                dwSize          = Marshal.SizeOf(typeof(UserNotificationTrigger)),
                dwType          = NotificationType.CNT_TIME,
                lpszApplication = appBuff,
                lpszArguments   = argsBuff,
                stStartTime     = SystemTime.FromDateTime2(start)
            };

            IntPtr handle = CeSetUserNotificationExNoType(IntPtr.Zero, ref trigger, IntPtr.Zero);

            Marshal.FreeBSTR(appBuff);
            Marshal.FreeBSTR(argsBuff);

            //TODO: fix this please

            if (handle == IntPtr.Zero)
            {
                throw new ExternalException(string.Format("Unable to schedule application launch {0}: {1} {2}", start, application, arguments));
            }
        }