Question

In: Computer Science

write a c# console application app that reads all the services in the task manager and...

write a c# console application app that reads all the services in the task manager and automatically saves what was read in a Notepad txt file.  Please make sure that this program runs, also add some comments

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. If not, PLEASE let me know before you rate, I’ll help you fix whatever issues. Thanks

using System;
using System.ServiceProcess; //for fetching services
using System.IO; //for writing to file

class FetchServices
    {
        static void Main(string[] args)
        {
            //getting an array of ServiceController objects which are the services currently
            //installed on this computer            
            ServiceController [] services = ServiceController.GetServices();
            //opening a file named services.txt for writing. change the file path or name
            //if you want to.
            string filename="services.txt";
            StreamWriter writer=new StreamWriter(filename);
            //looping through each service in the array
            for(int i=0;i<services.Length;i++){
                //if service is currently running, writing the name of service to the
                //output file. if you want to write all services instead of currently
                //running ones, remove the if statement and use only the below line
                //writer.WriteLine(services[i].DisplayName);
                if(services[i].Status==ServiceControllerStatus.Running){
                    writer.WriteLine(services[i].DisplayName);
                }
                
            }
            //closing the writer, saving changes
            writer.Close();
            //alerting user to check services.txt and exiting
            Console.WriteLine("services list has been written to the file: "+filename+", please check.");
        }
    }

/*generated services.txt file screenshot (partial)*/



Related Solutions

Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the...
Shopping Cart App (C#) Please create a C# Console (.NET Framework) application which reads from the user, the price of items in their shopping "cart". Be sure to tell the user how to stop (or ask them if they want to stop) entering prices. Items can be priced any positive number greater than zero. When the user has entered the prices for all items in their "cart", calculate the subtotal (the sum of all item prices). Next, check if the...
IN C# lang Write a console app (review Module 5 for console app) that stores 3...
IN C# lang Write a console app (review Module 5 for console app) that stores 3 students test stores in 3 separate arrays as integers. Some did not not take all the tests, so they each have a their own length and we use separate arrays. Declare and initialize each array. Use meaningful names. Print each array as follows: Morgan 98, 72, 65 Bowie 15, 47, 35, 92, 94 Ananya 91, 68, 87, 75 Extra credit: Compute the average for...
In VB console write a Console Application that reads an input value for ??. You can...
In VB console write a Console Application that reads an input value for ??. You can assume that the user only inputs numeric values.
Write a Java console application that reads a string for a date in the U.S. format...
Write a Java console application that reads a string for a date in the U.S. format MM/DD/YYYY and displays it in the European format DD.MM.YYYY  For example, if the input is 02/08/2017, your program should output 08.02.2017
Create a console app c#. Using a List, ask the user to enter all of their...
Create a console app c#. Using a List, ask the user to enter all of their favorite things. Once they are done, randomly pick a value from the list and display it.
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and...
Find MIN. Write a C# console app consisting of class MIN with the method CalculateMin() and the driver class. Print the MIN and MIN's location. Don't count numbers outside the range [0, 100].
C# Write a console application that takes the following passage and removes every instance of the...
C# Write a console application that takes the following passage and removes every instance of the word "not" using StringBuilder and prints the result out to the console: I do not like them In a house. I do not like them With a mouse. I do not like them Here or there. I do not like them Anywhere. I do not like green eggs and ham. I do not like them, Sam-I-am. Ensure that the resulting output reads normally, in...
Loops Write a simple C/C++ console application that will calculate the equivalent series or parallel resistance....
Loops Write a simple C/C++ console application that will calculate the equivalent series or parallel resistance. Upon execution the program will request ether 1 Series or 2 Parallel then the number of resisters. The program will then request each resistor value. Upon entering the last resistor the program will print out the equivalent resistance. The program will ask if another run is requested otherwise it will exit.
write C# console app No arrays Credit card validation Problem. A credit card number must be...
write C# console app No arrays Credit card validation Problem. A credit card number must be between 13 and 16 digits. It must start with: –4 for visa cards –5 for mater cards –37 for American express cards –6 for discover cards •Consider a credit card number 4380556218442727 •Step1: double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number. •Step2: now add...
Create a console app with C# that uses a while loop to calculate the average of...
Create a console app with C# that uses a while loop to calculate the average of 3 test scores. Input integers, but use the appropriate average data type. Generally, you use a while to do something while a condition is true. You can use a while loop to execute a certain number of times. *While* this is not the best use of the while loop and another loop is generally more appropriate, it follows the pattern below set a counter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT