Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard way to access the windows services file in .Net?

Is there a standard way in .Net to access and modify the windows services file? Right now I'm just accessing the file via a stream and writing to the file like I would for any other file. The file is located in c:\windows\system32\drivers\etc\, but I'm worried that this may change in 64 bit versions of Windows or may vary in different versions of Windows (I could be wrong and admittedly, I haven't looked into this very much yet). Aside from that, I'm just wondering if there is a standard way, say via WMI and/or the System.Management namespace, to find and modify the services file.

The actual specifics of what I need to do is to check if certain database aliases used for our software are specified for the expected ports. If not, add them.

like image 540
Jason Down Avatar asked Dec 30 '09 14:12

Jason Down


People also ask

How do I access Windows services?

Press the Win + R keys on your keyboard, to open the Run window. Then, type "services. msc" and hit Enter or press OK. The Services app window is now open.

Where are Windows Service files stored?

The Services file is typically located in %windir%\System32\drivers\etc\services. If the file is missing, check with your system administrator before starting the database server installation process.

Does .NET Core support Windows Service?

NET Core and . NET 5+, developers who relied on . NET Framework could create Windows Services to perform background tasks or execute long-running processes. This functionality is still available and you can create Worker Services that run as a Windows Service.


1 Answers

An open source project called System.Peppers has a class doing this.

There is a registry key that contains the full path to the files you are editing.

Here is a link to the exact class: HostFile class

like image 74
jonathanpeppers Avatar answered Oct 30 '22 10:10

jonathanpeppers