Riddler667
New member
- Joined
- Aug 16, 2022
- Messages
- 2
- Programming Experience
- Beginner
Hello Im a beginner at C# coding and trying to make a simple cmd prompt that shows the status of a service running. Below is my code with the exception listed. Ive tried alot of different solutions with no avail. Please let me know if you can help out.
C#:
using System.ServiceProcess;
using System.Net;
using System.Data;
using System.Threading.Tasks;
static string GetWindowsServiceStatus(String SERVICENAME)
{
ServiceController sc = new ServiceController(SERVICENAME);
switch (sc.Status)
{
case ServiceControllerStatus.Running:
return "Running";
case ServiceControllerStatus.Stopped:
return "Stopped";
case ServiceControllerStatus.Paused:
return "Paused";
case ServiceControllerStatus.StopPending:
return "Stopping";
case ServiceControllerStatus.StartPending:
return "Starting";
default:
return "Status Changing";
}
}
namespace DNAChecker
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("DNADrvr32 Status: " + GetWindowsServiceStatus("DNADrvr32")); ----- CS8801 Cannot use local variable or local function 'GetWindowsServiceStatus' declared in a top-level statement in this context.
Console.ReadLine();
}
catch (Exception ex) { }
}
}
Last edited by a moderator: