Advertisement

07.17.2003 at 11:51AM PDT, ID: 20681874
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.8

NTSvc.ocx won't process shutdown event

Asked by bartsmit in Visual Basic Programming

I guess most experts here will be familiar with the ntsvc.ocx and its many sample programs. I have created a service with this which runs great. The *only* problem is that the service needs to tidy up some stuff on shutdown.

For the life of me, I cannot get the shutdown event to be handled. I have attached a sample app which runs off a form with the ntsvc.ocx, a timer and a status bar control. The only modifications that I've made to the sample code are a series of beep statements. The service happily beeps once for start and twice for stop. However it does not make a sound when the machine reboots.  I'd be really happy if somebody can hack it so it gives three beeps just before Windows shuts down.

I have tried adding a NTService1_Shutdown() handler,  Form_UnloadQuery() and Form_Unload() subs but I cannot get the service to run code on shutdown.

This is bugging me and I really like to fix this badly, hence the high point value. Any sample code that runs something on a reboot is fine, as I need to port it back to my main project anyway. My real code doesn't have .interactive=true and only outputs to the app log.

Thanks

===================== sample code ===============
Option Explicit
Private Sub Form_Load()
On Error GoTo Err_Load
    Dim strDisplayName As String
    Dim bStarted As Boolean
    strDisplayName = NTService1.DisplayName
    StatusBar.Panels(1).Text = "Loading"
    If Command = "-install" Then
        ' enable interaction with desktop
        NTService1.Interactive = True
        If NTService1.Install Then
            Call NTService1.SaveSetting("Parameters", "TimerInterval", "1000")
            MsgBox strDisplayName & " installed successfully"
        Else
            MsgBox strDisplayName & " failed to install"
        End If
        End
    ElseIf Command = "-uninstall" Then
        If NTService1.Uninstall Then
            MsgBox strDisplayName & " uninstalled successfully"
        Else
            MsgBox strDisplayName & " failed to uninstall"
        End If
        End
    ElseIf Command = "-debug" Then
        NTService1.Debug = True
    ElseIf Command <> "" Then
        MsgBox "Invalid command option"
        End
    End If
    Timer.Interval = CInt(NTService1.GetSetting("Parameters", "TimerInterval", "2000"))
    ' enable Pause/Continue. Must be set before StartService
    ' is called or in design mode
    NTService1.ControlsAccepted = svcCtrlPauseContinue + svcCtrlShutdown
    ' connect service to Windows NT services controller
    NTService1.StartService
Err_Load:
    Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub

Private Sub NTService1_Continue(Success As Boolean)
On Error GoTo Err_Continue
    Timer.Enabled = True
    StatusBar.Panels(1).Text = "Running"
    Success = True
    Call NTService1.LogEvent(svcEventInformation, svcMessageInfo, "Service continued")
Err_Continue:
    Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub

Private Sub NTService1_Control(ByVal lngEvent As Long)
On Error GoTo Err_Control
    Beep
    Beep
    Beep
Err_Control:
    Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub


Private Sub NTService1_Pause(Success As Boolean)
On Error GoTo Err_Pause
    Timer.Enabled = False
    StatusBar.Panels(1).Text = "Paused"
    Call NTService1.LogEvent(svcEventError, svcMessageError, "Service paused")
    Success = True
Err_Pause:
    Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub


Private Sub NTService1_Start(Success As Boolean)
On Error GoTo Err_Start
    Beep
    StatusBar.Panels(1).Text = "Running"
    Success = True
Err_Start:
    Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub


Private Sub NTService1_Stop()
On Error GoTo Err_Stop
    Beep
    Beep
    StatusBar.Panels(1).Text = "Stopped"
    Unload Me
Err_Stop:
    Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub


Private Sub Timer_Timer()
On Error GoTo Err_Timer
    StatusBar.Panels(2).Text = Format(Now(), "hh:mm:ss")
Err_Timer:
    Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End SubStart Free Trial
[+][-]07.17.2003 at 12:23PM PDT, ID: 8945733

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2003 at 03:46PM PDT, ID: 8947463

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.17.2003 at 04:41PM PDT, ID: 8947900

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.17.2003 at 04:47PM PDT, ID: 8947931

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2003 at 02:43AM PDT, ID: 8950324

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.18.2003 at 03:09AM PDT, ID: 8950485

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.18.2003 at 06:13AM PDT, ID: 8951439

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2003 at 08:33AM PDT, ID: 8952707

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2003 at 10:13AM PDT, ID: 8953599

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.18.2003 at 10:33AM PDT, ID: 8953747

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.18.2003 at 02:46PM PDT, ID: 8955561

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.21.2003 at 03:09AM PDT, ID: 8966150

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.21.2003 at 03:18AM PDT, ID: 8966185

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.21.2003 at 05:54PM PDT, ID: 8972300

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2003 at 02:07AM PDT, ID: 8974695

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2003 at 04:22AM PDT, ID: 8975411

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2003 at 06:31PM PDT, ID: 8981844

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2003 at 06:39PM PDT, ID: 8981892

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Visual Basic Programming
Sign Up Now!
Solution Provided By: Teodor
Participating Experts: 3
Solution Grade: A
 
 
[+][-]07.24.2003 at 02:16AM PDT, ID: 8993504

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2003 at 03:34AM PDT, ID: 8993831

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.08.2003 at 11:16PM PDT, ID: 9316386

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32