Featured Post

Smart Product designer

Image
download and purchase link: https://alkanyx.com/item/49/Smart+Product+designer

Live preview : http://smartproductdesigner.000webhostapp.com/

Smart Product Designer is a  tool to create your own product and get directly from your website. It is well documented, very easy to customize and use. It is build using most advance technologies including javascript, jQuery and html5.
Features Choose different product from collectionAdd custom texts to product.Change text colorChange the size and font of the TextLet the user drag, move or remove elementsAdd images to product selected from art gallery or browse it from systemDesign both frontside and back-sideShows preview while designingDownload designVery easy to customize and useHere is the purchase link : https://alkanyx.com/item/49/Smart+Product+designer

Enable, Disable and Start the task of task scheduler in C#.Net

Below function demonstrates how to enable, disable and run the already created scheduled task. It will first check if the task exists in task scheduler:


public static void updateUserTaskInScheduler(string action)
        {
            try
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = "/C schtasks /query /TN <<TaskNameWithQuotes>>; //Check if task exists
                startInfo.RedirectStandardOutput = true;
                startInfo.UseShellExecute = false;
                startInfo.CreateNoWindow = true;
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                if (System.Environment.OSVersion.Version.Major < 6)
                {
                    startInfo.Verb = "runas";
                }
                using (Process process = Process.Start(startInfo))
                {
                    // Read in all the text from the process with the StreamReader.
                    using (StreamReader reader = process.StandardOutput)
                    {
                        string stdout = reader.ReadToEnd();
                        if (stdout.Contains("<<TaskName>>")) //If task exists
                        {
                            startInfo.RedirectStandardOutput = false;
                            startInfo.UseShellExecute = true;
                            switch (action)
                            {
                                case "Enable":
                                    startInfo.Arguments = "/C schtasks /Change /TN <<TaskNameWithQuotes>>  /Enable";
                                    break;

                                case "Disable":
                                    startInfo.Arguments = "/C schtasks /Change /TN <<TaskNameWithQuotes>> /Disable";
                                    break;

                                case "Run":
                                    startInfo.Arguments = "/C schtasks /RUN /TN <<TaskNameWithQuotes>> ";
                                    break;
                            }
                            Process.Start(startInfo).WaitForExit();
                        }
                        else
                        {
                             //Task doesnot exist
                        }
                        stdout = null;
                        reader.Close();
                        reader.Dispose();
                    }
                }
                startInfo = null;
            }
            catch (Exception ex)
            {
                    MessageBox.Show(ex.Message);
            }
        }

The above function can be called in the below manner:

1. To run the task:
            updateUserTaskInScheduler("Run");

2. To enable the task:
            updateUserTaskInScheduler("Enable");

3. To disable the task:
            updateUserTaskInScheduler("Disable");

Comments