code not running in service

red_ghost

Member
Joined
Mar 13, 2007
Messages
13
Location
Green Bay WI
Programming Experience
3-5
I created a service and have it setup as a local service. When the service runs, I start a timer with a 5 second interval. What it does, is it goes through and makes sure a program is running, and if it isnt, it will start it. But this doesn't seem to be happening.

Here is the code for it:

Dim cnt As Integer = 0
Try
cnt = UBound(Process.GetProcessesByName("AlcanProcessor")) + 1
Catch ex As Exception
End Try
If cnt = 0 Then
Dim p As New Process
Dim pass As New System.Security.SecureString
Dim c As System.Char
For Each c In "Password"
pass.AppendChar(c)
Next
Process.Start("C:/Program Files/DDSi/AlcanProcSetup/AlcanProcessor.exe", "Admin", pass, "necsrv01")
End If

I have the same code setup to a button in another program that I was using to test it, and it works fine in there.
 
Imports System.Diagnostics
Public Class Service1
Protected Overrides Sub OnStart(ByVal args() As String)
Timer1.Enabled =​
True
End Sub
Protected Overrides Sub OnStop()
Timer1.Enabled =​
False
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim cnt As Integer = 0
Try
cnt = UBound(Process.GetProcessesByName(​
"AlcanProcessor")) + 1
Catch ex As Exception
End Try
If cnt = 0 Then
Dim p As New Process
Dim pass As New System.Security.SecureString
Dim c As System.Char
For Each c In "Password"
pass.AppendChar(c)
Next
Process.Start("C:/Program Files/DDSi/AlcanProcSetup/AlcanProcessor.exe", "Admin", pass, "necsrv01")
End If
End Sub
End Class
 
Back
Top