Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 5th, 2003, 10:56 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default NTSVC.OCX app and Windows 2000

Hello, All!

I am trying to get service written in VB using NTSVC.OCX start at boot time. No success so far - after 30 seconds timeout it leaves message 7000 in Event log (system) - Timeout waiting for service <servicename> to connect.
Service starts OK manually.

Anyone knows the trick how to get it work at boot time?

Thanks,

PS I did not write it nor decided it to be that way... :)

 
Old November 5th, 2003, 11:16 AM
Friend of Wrox
 
Join Date: Aug 2003
Posts: 205
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The service control can be a bit tricky. Please post your code for automatic so we can look it over.
 
Old November 5th, 2003, 11:39 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nothing special there, just code similar to that in MSDN example.
There is a hidden form with NTSVC and timer on it.

It starts perfectly on NT but not on W2k...

Would love it be something really stupid on my side...

Thanks,

Code:
Private Sub Form_Load()

On Error GoTo Oops

    Select Case UCase(Command)
        Case "-I", "/I"
             If NTService.Install Then
                 MsgBox NTService.DisplayName & " installed."
             Else
                 MsgBox NTService.DisplayName & " NOT installed."
             End If
             Unload Me
        Case "-U", "/U"
             If NTService.Uninstall Then
                 MsgBox NTService.DisplayName & " deinstalled."
             Else
                 MsgBox NTService.DisplayName & " NOT deinstalled."
             End If
             Unload Me
        Case ""
             '-- This code should only run when the
             '   application is started without parameters
             NTService.ControlsAccepted = svcCtrlPauseContinue + _
                                          svcCtrlStartStop + _
                                          svcCtrlShutdown

             If NTService.StartService Then
                 Call NTService.LogEvent(svcEventInformation, svcMessageInfo, _
                    NTService.DisplayName & " started OK.")
             Else
                Call NTService.LogEvent(svcEventError, svcMessageError, _
                    "[" & Err.Number & "] " & Err.Description)
             End If
        Case Else
             '-- This code should only run when the
             '   application is started with invalid
             ' Parameters
             MsgBox "Parameter: " & Command & _
                    " not understood. Use –I " & _
                    " (install service) or –U (deinstall service)."
             Unload Me
    End Select

Exit Sub

Oops:

    If NTService.Interactive Then
        MsgBox "[" & Err.Number & "] " & Err.Description
    Else
        Call NTService.LogEvent(svcEventError, svcMessageError, "[" _
            & Err.Number & "] " & Err.Description)
    End If

End Sub
 
Old November 10th, 2003, 02:16 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default

First of all could you check the StartMode property for NTService control. It must be 2 - svcStartAutomatic.
Secondly, do you have a Timer to start the service? If you do have the timer did you set any TimerInterval?
         -Dmitriy
 
Old November 11th, 2003, 03:16 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Dmitriy,

Yes, it is set to start automatically at design time, in properties for NTSVC control. Should that be done at runtime too? Service starts OK on Windows NT...

Yes, timer has Interval property set both at design time (initial delay) and then in Start event from value retained in registry (working delay). That way I can tune service starts.

Thank You,

Felix

 
Old November 12th, 2003, 09:48 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default

No, you do not have to set the Mode in run-time if you already set it in design time.
Set the timer interval in design mode to 0 and reset it to whatever you want (=1000) inside the NTService1_Start procedure:

Private Sub NTService1_Start(Success As Boolean)
On Error GoTo Err_Start

    Success = True

    'do some coding if you need here

    tmrEvent.Interval = 10000 'set interval

Err_Start:
    'error handling here
End Sub

and also add this code after the End Select statement inside your Form_Load() procedure:

        ' enable Pause/Continue. Must be set before StartService
        ' is called or in design mode. svcCtrlPauseContinue = 2 (predefined constant)
        NTService1.ControlsAccepted = svcCtrlPauseContinue

        ' connect service to Windows NT services controller
        NTService1.StartService

        'Initialize the timer variables
        tmrEvent.Interval = 10000 'set interval

    -Dmitriy
 
Old November 12th, 2003, 10:16 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No, that does not help.

I changed NTService1_Start event code as you suggested and added yet another NTService1.StartService into Form_Load procedure.

Must confess that I had fingers crossed when I restarted the PC...

Now I have got under impression that I will never get it to work... :(

Thanks for your help anyway,

Felix

 
Old November 13th, 2003, 02:37 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 121
Thanks: 1
Thanked 0 Times in 0 Posts
Default

OK Felix,
give me your contact information and I will send the example of the source code to you to help:D
       -Dmitriy
 
Old November 14th, 2003, 03:16 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here it goes - [email protected]

I will compile it, register and try on restart...

Felix
 
Old November 15th, 2003, 05:07 AM
Registered User
 
Join Date: Oct 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

As I said in e-mail - Your code works OK on my W2k station. This ruled out environmental problems.

Now when I started to modify code for MY service some strange things surfaced.

1. My service did not have any code for NTService_Control event. So I added empty sub and put a call to NTService.LogEvent like this

Code:
    Call NTService.LogEvent(svcEventInformation, _
                            svcMessageInfo, _
                            NTService.DisplayName & " Control.")
Additionally I put similar calls to write to registry for Start event.

Make/Copy/Restart - not good.

No entries in Eventlog for my service at all. That made me think that Form_Load code was not executed.

2. When I went back to project after restart, line
Code:
Private Sub NTService_Control(ByVal Event As Long)
was in error. Strange I thought. Re-inserted sub definition using dropdown and copied code for sub. Empty sub in error removed.

Make/Copy/Restart - not good. Same with eventlog - no messages, except two stating error in System section.

3. Then I noticed that my service had Initialize event for a form.

So, with little in mind, I added

Code:
    Call NTService.LogEvent(svcEventInformation, _
                            svcMessageInfo, _
                            NTService.DisplayName & " Control.")
as first code lines for that event.

Make/Copy/Restart - MIRACLE! It works!!!

So I have service starting on bootup. I will have to exercise great care on subsequent modifications in order to retain that behaviour... ;)

Many thanks, Dmitriy for your help, you are such a great person!!!

Regs,

Felix





Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing Windows service from a windows app sajid08 C# 1 October 6th, 2006 10:25 AM
Use of NTSVC.OCX jmtoet Pro VB 6 12 June 7th, 2005 05:00 PM
Windows 98 OCX control issues vs Windows XP benoyraj VB How-To 0 May 5th, 2004 08:10 AM
Windows 2000 and SQL 2000 in Korean Language mipo SQL Server 2000 0 February 19th, 2004 12:50 PM
NTSVC.OCX and Error = 91 skhan22 Pro VB 6 3 October 24th, 2003 01:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.