views:

162

answers:

3

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.

A: 

Use the System.Management.Instrumentation namespace

Sample code here http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=114

DalSoft
A: 

you can use System.Environment.SystemDirectory to get to the sys32 folder

sagie
+1  A: 

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

Jonathan.Peppers
Nice work Jonathan. That's a sweet library you've got going on there. Thanks!
Jason Down