简体   繁体   中英

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.

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

Use the System.Management.Instrumentation namespace

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

您可以使用System.Environment.SystemDirectory来访问sys32文件夹

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM