Morning Guys and Girls.
I am using the below code to query the status of a service, the only problem comes when you try to pull the status for a hostname and ithe currently logged in user doesn't have permissions.
I have been trying to work out a way I can add in a username and password function so details can be inserted for a user that does have persmissions. basically a "Run as" way of doing things.
Any pointers?
Try
Dim ServName As String = txtServiceName.Text
Dim HostName As String = txtHostName.Text
Dim sqlSvc As ServiceController
sqlSvc = New ServiceController(ServName, HostName)
If sqlSvc.Status.ToString.Equals("Running") Then
lblServiceStatus.Text = ("Service: " & sqlSvc.Status.ToString)
Else
lblServiceStatus.Text = ("Service: " & sqlSvc.Status.ToString)
End If
Catch ex As Exception
lblServiceStatus.Text = "Error: " & Err.Description
End Try
Cheers!