none
Working on a form that will check if a user defined service is running

    Question

  • I found some c# code that might work but I need help translating it into VB

    Imports System.ServiceProcess
    
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles getProccess.Click
    
    
    
            Dim services = ServiceController.GetServices().Where(Function(x) x.Status = ServiceControllerStatus.Running).ToList()
    
            For i As var = 0 To services.Count() - 1
                Dim serviceName = services(i).DisplayName.ToLower()
            Next
    
    
            Dim isRunning = ServiceController.GetServices().Where(Function(x) x.Status == ServiceControllerStatus.Running && x.DisplayName == proccessName).Any()
    
    
    
        End Sub
    
        Private Sub proccessName_TextChanged(sender As Object, e As EventArgs) Handles processName.TextChanged
    
        End Sub
    End Class
    
    I added the import but I am getting syntax errors elsewhere.
    I want to the text box processname to be where the user inputs the service name and the button to be a "get status" type button. Any suggestions?

    Monday, March 13, 2017 3:06 AM

All replies

  • Check if the System.ServiceProcess reference is present.

    Project -> Add Reference... -> Framework

    Monday, March 13, 2017 3:45 AM
  • It is! First line in the block :)
    Monday, March 13, 2017 4:55 AM
  • Is that the same? I thought some had to be, when I'm not sure I guess.
    • Edited by George-Frias Monday, March 13, 2017 5:09 AM clarity
    Monday, March 13, 2017 5:07 AM
  • It is! First line in the block :)

    If you are referring to the imports statement, that is not a reference.  You need to make sure that the namespace has been included in the project as a reference - Project -> Add Reference... -> Framework. 

    What is the error message? - that probably tells you that the reference is missing.

    Monday, March 13, 2017 6:03 AM