Link to home
Start Free TrialLog in
Avatar of MiketheD
MiketheD

asked on

Windows 2003 Custom Service

All,

I'm trying to use VB.NET to monitor an application on a WK2003 Server. Basically I would like the service to determine how long that process is running and if its been running for more than 5 minutes then terminate it like you would from task manager. I only know the name of the process. Is this possibile? I have VB.NET Studio 2005.

Thanks in advance,

Mike
Avatar of 3_S
3_S

Replace YourServiceName with the actual name.
Is a restart required? or you just want to stop the service?

I don see the point in stopping a service that runs for 5 minutes. Can you not add the program as a scheduled task and terminate it after 5 minutes?

otherwise if it is just a process and not a service
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("YourProcessName")
For Each p As Process In pProcess
p.Kill()
Next
Imports System.ServiceProcess
Dim myService  As ServiceController
myService  = New ServiceController("YourServiceName")

Dim sStatus As String
myService .Refresh()

Try
   If myService .CanStop Then
      myService .Stop()
      myService .Refresh()
      myService .Start()
   else
      msgbox "Service can not be stopped"
   End If
Catch exp As Exception
   MsgBox("error occured")
End Try

myService.Refresh()
sStatus = myService.Status.ToString
Msgbox "Status of service: " & sStatus

Open in new window

Avatar of MiketheD

ASKER

3 S:,

Thanks for the fast reply... Here is the problem I want to solve... I work for a retailer that has a server and a desktop PC. In a nutshell when the user from the desktop runs a report it fires a process called grindq.exe ON the server. This process hangs quite a bit and the only way to get the reports to work again is to terminate the process. I was hoping to create a service that will monitor anytime the "grindq.exe" is launched on the server and if it runs for more than 5 mins terminate it. Hope this makes sense....

Thanks,

Mike
ASKER CERTIFIED SOLUTION
Avatar of 3_S
3_S

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
3_S:,

The report is run from POS software of which I have limited knowledge due to the propriety nature of the system. The code to kill the process makes sense but since they run that report at various times throughout the day, is there a way to check how long a process has been running? I can then write a service that checks every so often to see if grindq.exe is resident & if it has been running longer than 5 minutes terminate it&.

Thanks,
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
3_S:

Thanks for the help, between your help and a bit of google I'm well on the way.

Mike