Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27409

Installed service times out

$
0
0
Good afternoon gang,

I have installed a service onto my local machine. It is a form based service that opens a web browser control and has automated clicks, and then opens a program and automates clicks with that to open up a report and save it. I am able to install the service that I wrote in visual studio express, but upon trying to start the service it just times out. i have already tried modding the registry for the servicetimeout to be 120 seconds but it doesn't wait that long either. using event logs and it doesnt throw an error anymore(it use to throw one but only because it would try to open a program that isnt on my machine since this will be going on my work computer. i have posted source code below with some modifications to protect sensitive data:


Declare Function SetCursorPos Lib "user32.dll" (ByVal x As Integer, ByVal y As Integer) As Integer
Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As POINTAPI) As Integer
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
Dim s As Integer


Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Dim yesterdaydate As DateTime
Dim hwd As Integer


Public Structure POINTAPI
Public x As Integer
Public y As Integer
End Structure







Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Dim p As POINTAPI
Dim I As Integer

I = GetCursorPos(p)
TextBox1.Text = CStr(p.x) & ", " & CStr(p.y)


End Sub





Public Sub main()


' Threading.Thread.Sleep(3000)
' s = SetCursorPos(921, 558)
' mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
' mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
' Threading.Thread.Sleep(3000)
' s = SetCursorPos(850, 648)
' mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
' mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
s = SetCursorPos(155, 125)
Threading.Thread.Sleep(5000)
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("username")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("password")
SendKeys.SendWait("{TAB}")
SendKeys.SendWait("{ENTER}")
Threading.Thread.Sleep(10000)
s = SetCursorPos(900, 184)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(3000)
s = SetCursorPos(900, 184)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(3000)
s = SetCursorPos(409, 414)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(3000)
'Process.Start("C:\Program Files\\win32_x86\programlaunch.exe")
Threading.Thread.Sleep(10000)
SendKeys.SendWait("password")
SendKeys.SendWait("{ENTER}")
Threading.Thread.Sleep(8000)
s = SetCursorPos(32, 58)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Threading.Thread.Sleep(2000)
s = SetCursorPos(32, 218)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(8500)
s = SetCursorPos(441, 36)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(20000)
s = SetCursorPos(760, 517)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
SendKeys.SendWait(yesterdaydate.ToString("yyyyMMdd"))
Threading.Thread.Sleep(2000)
s = SetCursorPos(760, 567)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
SendKeys.SendWait(yesterdaydate.ToString("yyyyMMdd"))
SendKeys.SendWait("{ENTER}")
Threading.Thread.Sleep(20000)
s = SetCursorPos(47, 60)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
s = SetCursorPos(69, 166)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(2000)
s = SetCursorPos(1021, 399)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
s = SetCursorPos(917, 426)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
s = SetCursorPos(1124, 612)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
s = SetCursorPos(948, 678)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
s = SetCursorPos(1182, 579)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
s = SetCursorPos(1084, 560)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(3000)
s = SetCursorPos(1906, 8)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Threading.Thread.Sleep(1000)
s = SetCursorPos(1111, 566)
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Process.GetCurrentProcess.Kill()













End Sub





Private Sub Timer2_Tick(sender As System.Object, e As System.EventArgs) Handles Timer2.Tick
Timer2.Enabled = False
yesterdaydate = DateTime.Today.AddDays(-1)
Dim t1 As New Threading.Thread(AddressOf main)
t1.Start()
End Sub


Public Sub simplekill()
Process.GetCurrentProcess.Kill()
End Sub





Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
AddHandler Me.FormClosing, AddressOf simplekill
End Sub
End Class

timer2 only waits about 3 seconds, I had to use a process kill upon program exit since exiting the program leaves the thread open and continues to control the mouse, and all other methods of letting the thread die naturally wouldnt be desirable (while loop would still execute rest of code etc.).

Here is my onstart from winservice.vb class

Imports System.IO
Namespace WinServiceProject

Class WinService
Inherits System.ServiceProcess.ServiceBase
' The main entry point for the process
Private Shared Sub Main()
Dim ServicesToRun As System.ServiceProcess.ServiceBase()
ServicesToRun = New System.ServiceProcess.ServiceBase() {New WinService()}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
''' <summary>
''' Required method for Designer support - do not modify
''' the contents of this method with the code editor.
''' </summary>
Private Sub InitializeComponent()
Me.ServiceName = "WinService"
End Sub
Private folderPath As String = "c:\temp"
''' <summary>
''' Set things in motion so your service can do its work.
''' </summary>
Protected Overrides Sub OnStart(args As String())
If Not System.IO.Directory.Exists(folderPath) Then
System.IO.Directory.CreateDirectory(folderPath)
End If
Dim fs As New FileStream(folderPath & "\WindowsService.txt", FileMode.OpenOrCreate, FileAccess.Write)
Dim m_streamWriter As New StreamWriter(fs)
m_streamWriter.BaseStream.Seek(0, SeekOrigin.[End])
m_streamWriter.WriteLine(" WindowsService: Service Started at " & DateTime.Now.ToShortDateString() & " " & DateTime.Now.ToShortTimeString() & vbLf)
m_streamWriter.Flush()
m_streamWriter.Close()
End Sub
''' <summary>
''' Stop this service.
''' </summary>
Protected Overrides Sub OnStop()
Dim fs As New FileStream(folderPath & "\WindowsService.txt", FileMode.OpenOrCreate, FileAccess.Write)
Dim m_streamWriter As New StreamWriter(fs)
m_streamWriter.BaseStream.Seek(0, SeekOrigin.[End])
m_streamWriter.WriteLine(" WindowsService: Service Stopped at " & DateTime.Now.ToShortDateString() & " " & DateTime.Now.ToShortTimeString() & vbLf)
m_streamWriter.Flush()
m_streamWriter.Close()
End Sub
End Class
End Namespace

Only thing is I have never seen c:\temp created(obviously, since it hangs before it ever starts the service. anyone have any ideas why this service wont start or am i implementing something incorrectly?

Viewing all articles
Browse latest Browse all 27409

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>