Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

VB .NET Services on remote machines...

Thread Tools
 
Search this Thread
 
Old 04 April 2002, 02:48 PM
  #1  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

I have been writing a windows service, I want to be able to connect to a remote machine and query a service... the following code works fine to a win2k machine but not nt4 any ideas?? Is this using wmi or similar??

Sub Main()
Dim MyController As ServiceController
MyController = New ServiceController("Spooler")
MyController.MachineName = "TEST01"
Dim sStatus As String
MyController.Refresh()
sStatus = MyController.Status.ToString
Console.WriteLine(MyController.ServiceName & " is in state:" & sStatus)


End Sub
Old 04 April 2002, 03:13 PM
  #2  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

Are you getting any exceptions thrown?
Old 04 April 2002, 03:27 PM
  #3  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

An unhandled exception of type 'System.InvalidOperationException' occurred in system.serviceprocess.dll

Additional information: Service Spooler was not found on computer 'cpl005055'.

David
Old 04 April 2002, 03:38 PM
  #4  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

Is Spooler listed if you call GetServices() ?

Current thoughts hinge around you not having browse permissions...
Old 04 April 2002, 03:48 PM
  #5  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

gimme a clue how to do that... just started playing with vb.net

David
Old 04 April 2002, 04:05 PM
  #6  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

F1 help have a look for "Retrieving Lists of Services".

This is a foreign language (I use C#) snippet:

Imports System
Imports System.ServiceProcess
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim services() As ServiceController, i As Integer
services = ServiceController.GetServices("cpl005055")
Me.ListBox1.Items.Clear()
For i = 0 To services.Length - 1
Me.ListBox1.Items.Add(services(i).ServiceName)
Next
End Sub
Old 04 April 2002, 04:11 PM
  #7  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

using the magic of copy & paste

Imports System
Imports System.ServiceProcess

Sub Main()
Dim services() As ServiceController, i As Integer
services = ServiceController.GetServices("cpl005055")
For i = 0 To services.Length - 1
Console.WriteLine("Service : " & services(i).ServiceName & " Found")
Next
End Sub

Keep an eye out for any exceptions and see if Spooler is tipped out to the console. Tell us what you see...

[Edited by MrDeference - 4/4/2002 5:12:30 PM]
Old 05 April 2002, 08:39 AM
  #8  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Service : Alerter Found
Service : AvSynMgr Found
Service : Browser Found
Service : ClipSrv Found
Service : CPQALERT Found
Service : CPQDMI Found
Service : DHCP Found
Service : EventLog Found
Service : EventSystem Found
Service : LanmanServer Found
Service : LanmanWorkstation Foun
Service : LmHosts Found
Service : LPDSVC Found
Service : McShield Found
Service : Messenger Found
Service : mnmsrvc Found
Service : MSIServer Found
Service : NAIMAGENT32 Found
Service : NALNTSERVICE Found
Service : NetDDE Found
Service : NetDDEdsdm Found
Service : Netlogon Found
Service : nmagent Found
Service : NtLmSsp Found
Service : PlugPlay Found
Service : ProtectedStorage Found
Service : Replicator Found
Service : RPCLOCATOR Found
Service : RpcSs Found
Service : Schedule Found
Service : SENS Found
Service : Spooler Found
Service : TapiSrv Found
Service : UPS Found
Service : WIN32SL Found
Service : WM Found

David
Old 05 April 2002, 09:08 AM
  #9  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

Erm, OK, what does this do?

Imports System
Imports System.ServiceProcess

Sub Main()
Dim services() As ServiceController, i As Integer
services = ServiceController.GetServices("cpl005055")
For i = 0 To services.Length - 1
Console.WriteLine("Service : " & services(i).ServiceName & " Found. Status: " & services(i).Status)
Next
End Sub
Old 05 April 2002, 09:25 AM
  #10  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Service : Alerter Found. Status: 1
Service : AvSynMgr Found. Status: 4
Service : Browser Found. Status: 1
Service : ClipSrv Found. Status: 1
Service : CPQALERT Found. Status: 4
Service : CPQDMI Found. Status: 4
Service : DHCP Found. Status: 4
Service : EventLog Found. Status: 4
Service : EventSystem Found. Status: 1
Service : LanmanServer Found. Status: 4
Service : LanmanWorkstation Found. Status: 4
Service : LmHosts Found. Status: 4
Service : LPDSVC Found. Status: 1
Service : McShield Found. Status: 4
Service : Messenger Found. Status: 4
Service : mnmsrvc Found. Status: 1
Service : MSIServer Found. Status: 1
Service : NAIMAGENT32 Found. Status: 1
Service : NALNTSERVICE Found. Status: 4
Service : NetDDE Found. Status: 1
Service : NetDDEdsdm Found. Status: 1
Service : Netlogon Found. Status: 4
Service : nmagent Found. Status: 1
Service : NtLmSsp Found. Status: 4
Service : PlugPlay Found. Status: 4
Service : ProtectedStorage Found. Status: 4
Service : Replicator Found. Status: 1
Service : RPCLOCATOR Found. Status: 1
Service : RpcSs Found. Status: 4
Service : Schedule Found. Status: 4
Service : SENS Found. Status: 1
Service : Spooler Found. Status: 1
Service : TapiSrv Found. Status: 1
Service : UPS Found. Status: 1
Service : WIN32SL Found. Status: 4
Service : WM Found. Status: 1

David
Old 05 April 2002, 09:45 AM
  #11  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

OK, that value on the end is the integer representation of the ServiceControllerStatus enumeration giving the running state:

Stopped 1
StartPending 2
StopPending 3
Running 4
ContinuePending 5
PausePending 6
Paused 7

If cpl005055 is the NT4 machine, and you have that output, you have all the info required. Just need to jig the code about a bit.
Old 05 April 2002, 09:53 AM
  #12  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

So, the short answer and the one that I should have written in the first post is that it looks like you should have called the overloaded constructor with the machine name and service:

Dim MyController As ServiceController
MyController = New ServiceController("Spooler", "TEST01")

In retrospect I should have spotted it earlier. Sorry.
Old 05 April 2002, 10:37 AM
  #13  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Not ideal but this combination works... I would prefer to specify the service name, but it just doesnt like it.

Sub Main()
Dim services() As ServiceController, i As Integer, d
services = ServiceController.GetServices("cpl005055")
For i = 0 To services.Length - 1
If services(i).ServiceName = "Spooler" And services(i).Status <> "4" Then
Try
services(i).Start()
Catch
Console.WriteLine("An Error Occurred Starting The Service")
End Try
End If
Next
End Sub

a couple of other things... please....

Do you know if you can send snmp alerts and messages the same as doing a net send easily...

Also if i have the service running and want to do something to do console.writeline to a console app that could run to monitor the status of the service, how would I do that? I dont need message queues do I?

David
Old 05 April 2002, 11:30 AM
  #14  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

Second one first,

use the TextWriterTraceListener (gulp!).

You need to use the IO namespace as well as the system.diagnostics one. Create a stream file and point the tracer to write to it (Trace.Listeners.Add). Thus when you call

System.Diagnostics.Trace... it will write it to the file.

This can also be done with the app.exe.config file, which is more in keeping with the ".NET way"

You will have to flush and close the file handle regulary
otherwise nothing will be written till the end of the app...

Re: SNMP alerts and net send alikes. You could just call the shellexecute API call. Not terribly elegant, granted. Other than that, I don't know...
Old 05 April 2002, 01:44 PM
  #15  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Excellent, that at least gives me something to go on... you've been a great help!!

David
Old 05 April 2002, 02:13 PM
  #16  
MrDeference
Scooby Regular
 
MrDeference's Avatar
 
Join Date: Mar 2002
Posts: 337
Likes: 0
Received 0 Likes on 0 Posts
Post

You're welcome, if you have any problems with it post here. I need to write a logger library for the stuff I am doing but it is fairly low priority at the moment...
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Abx
Subaru
22
09 January 2016 05:42 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
28 December 2015 11:07 PM
Mattybr5@MB Developments
Full Cars Breaking For Spares
12
18 November 2015 07:03 AM



Quick Reply: VB .NET Services on remote machines...



All times are GMT +1. The time now is 09:01 AM.