首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编写涉及ServiceController的函数

编写涉及ServiceController的函数
EN

Stack Overflow用户
提问于 2011-05-19 23:21:45
回答 1查看 363关注 0票数 0

我想要从这个块输出的文件中读取每一行文本。然后,每一行都与服务控制器一起使用,以输出在该计算机上运行的服务列表。

代码语言:javascript
复制
Dim de As New DirectoryEntry()
    'Name place to write file to
    Dim strFile As String = "C:\DomainUsers.txt"
    Dim fileExists As Boolean = File.Exists(strFile)

    'get list of all users on domain and write to file
    de.Path = "WinNT://domain.com"
    'Write each user to a text file as List
    Using sw As New StreamWriter(File.Open(strFile, FileMode.OpenOrCreate))
        MsgBox("Writing all Users to Memory, Click OK and wait for Window to Close")
        For Each d As DirectoryEntry In de.Children()
            sw.WriteLine(d.Name)
        Next
        Console.Clear()
    End Using

    'Reopen File and read each line
    'Return List of Processes for each User in Overwritefashion to New Version of File
    Using sr As New StreamReader(File.Open(strFile, FileMode.Open))
        Dim InstalledServices As List(Of String) = GetInstalledServices(sr.ReadLine.Trim)
    End Using

End Sub

'Lost as to how to go about using this function...
Function GetInstalledServices(ByVal Computer As String) As List(Of String)

End Function
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-19 23:35:26

你得检查一下,但它会是这样的。

代码语言:javascript
复制
Function GetInstalledServices(ByVal Computer As String) As List(Of String)

  Dim RetVal as New List(Of String)
  Dim scServices() As ServiceController()

  Try
      scServices = ServiceController.GetServices(Computer)

  For Each Svc as ServiceController In scServices

    RetVal.Add(Svc.ServiceName)

  Next

  Catch Ex as Exception
  End Try


  Return RetVal

End Function
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6060978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档