?
Solved

VB6 service starts automatically at bootup then stops

Posted on 2005-03-14
13
Medium Priority
?
1,598 Views
Last Modified: 2012-05-05
Hi,

I've written a VB6 Service using NTSVC.OCX. It works fine and I can start and stop it manually from the Services Applet (once I've installed it with /i  parameter that I put in the code). If I log off and log on again it works OK too, and the icon appears back in the systray everytime....

BUT if I set it to run as Automatic from the Services Applet and then I reboot the machine it starts at bootup, along with all the various other services but then stops. I'm running XP PRO SP2 with the free ZoneAlarm(set to allow my prog to run) and free AVG anti-virus

What is going on?

Ta in advance
Iain
0
Comment
Question by:iaing1000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 13536476
>>BUT if I set it to run as Automatic from the Services Applet and then I reboot the machine it starts at

Do you run as system account and allow service to inbteract with desktop is checked?
0
 

Author Comment

by:iaing1000
ID: 13536520
Hi,

It's running in the Local System Account and the corresponding interact with desktop box is checked

Iain
0
 

Author Comment

by:iaing1000
ID: 13536652
Hi

Also I gave it to someone else not running ZonAlarm (but with other firewall and anti-virus software running and it did the same there).

Iain
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:gbzhhu
ID: 13536697
What do you see in the event viewer.  Any entries for your service?
0
 

Author Comment

by:iaing1000
ID: 13536880
No entries for it ever at all, whether I start it manually (when it works perfectly) or whether started temporarily befoere stopping at bootup when it's set to automatic

Iain
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13537035
0
 
LVL 12

Accepted Solution

by:
gbzhhu earned 1600 total points
ID: 13537182
I use the NTSVC and I know I had to return the Start event so the controller knew the service started OK.  Are you doing the same?  Why don't you write to the logs as service starts so you know what is happening below is my Start sub

Private Sub NTSVC_Start(Success As Boolean)
'******************************************************************************************************
' Description   : Called from the services controller when the service is started
'               : This routine must return so the services controller knows the service has
'               : started correctly. This is achieved through the use of a timer
'******************************************************************************************************
On Error GoTo errorhandler
    Call EventLog(0, fDisplayName & " service started", "NTSVC_Start", svcEventInformation)
   
    TimerGO.Enabled = True
    TimerGO.Interval = 1000
    Success = True
   
exitproc:
    Exit Sub
errorhandler:
    Call EventLog(Err.Number, Err.Description, Err.Source, svcEventError)
    GoTo exitproc
    Success = False
End Sub

Public Sub EventLog(lNumber As Long, sDescription As String, sSource As String, SvcEventType As NTService.SvcEventType)
On Error Resume Next

Dim Msg As String

    If lNumber <> 0 Then
        Msg = lNumber & vbCr
    End If

    Msg = Msg & "Description: " & sDescription & vbCr
    Msg = Msg & "Source: " & sSource & vbCr
    Msg = Msg & "Stack: " & stack.GetStack
   
    Call LogEvent(SvcEventType, svcMessageInfo, Msg)
End Sub
0
 

Author Comment

by:iaing1000
ID: 13538053
Hi,

I've had a look at the link before shijusn, but I've never had any problems with NTSVC.ocx in the past(well only beeen using it 2 months!). Every time I solve a problem running NTSVC.ocx there have been people telling me it's unstable (even though this could of course be the reason!), so I'll treat that as a last resort.

Yes gbzhhu, I have code in my start event(just to really log in the event log that it started) but it doesn't seem to be writing it in any instance (ie when it fails as automatic on bootup, or even when I run it successfully from the applet without any reboot). I go to event viewer in administrative tools from control panel (is that correct?) and look aT System log. Strange, it used to write to it before XP PRO SP2......should I be looking somewhere else for the log????

Private Sub NTService_Start(success As Boolean)
    'Start Event Request
    On Error GoTo ServiceError
    lblServiceStatus.Caption = "Running"
    'MsgBox "Start"
    success = True
    NTService.LogEvent svcEventSuccess, svcMessageInfo, "Service paused"
    Exit Sub
ServiceError:
    NTService.LogEvent svcMessageError, svcEventError, "START: [" & Err.Number & "] " & Err.Description
End Sub

Ta
Iain
0
 
LVL 12

Expert Comment

by:gbzhhu
ID: 13543045
You are looking at the right place for the event log, although I wiould check the Application log instead of the System log.

I have been using NTSVC for our app for almost 2 years now on Win 2k and had no problem at all with it
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 400 total points
ID: 13543727
You can go this page

http://vbwire.com/advanced/howto/service2.asp


and download the source code for ocx and add more debug statement and see what happen
0
 

Author Comment

by:iaing1000
ID: 13567807
Hi,

That code works from the link, as does mine now. I discovered that if I don't make the call in Form_Load.....

Call RasEnumEntriesA(vbNullString, vbNullString, RAS(0), plSize, plEntries)

....then it all works fine. The above was being called from Form_Load when it starts up on bootup (the service just dropped out basically and stopped). If I were to start the service manually after bootup (from the services applet) then it would run OK. I have overcome the problem by having the call to RASEnumEntries happen on a timer after 60 secs. This way all the other services including firewalls, virus checkers etc. are up and running by the time it makes this call.

Whilst I've kinda sorted it, I'd like to know why this call fails. The call basically populates RAS( ), an array of a public type comprising a Long and a String, with the ID number and string names of all the DUNs stored in IE for dial-ups. Perhaps IE hadn't yet initialised? I'm lost!
 
Iain
0
 
LVL 12

Expert Comment

by:gbzhhu
ID: 13573065
Something similar happened to me before and that is why I have the timer in the code I posted above.  My feeling is that the service controller wants a response or will timeout if you put a timer in the start event and do nothing else but set the success to true then enable the timer control goes back to the service controller who is then happy and for us our timer timer event will fire and we will do whatever then.  I thought you had figured out why I had a timer in my start event
0
 

Author Comment

by:iaing1000
ID: 13573337
Hi,

Yes indeed it works fine now, I make the call to RASEnumEntriesA in the timer code, since the timer seems to allow control to be returned. I overlooked the significance of the timer stuff in your code initially, it was only on this post that it clicked.

Thanks
Iain
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question