Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB6 service starts automatically at bootup then stops

Posted on 2005-03-14
13
Medium Priority
?
1,600 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

580 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