Results 1 to 10 of 10

Thread: VB Program Run as NT Service [Resolved]

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    VB Program Run as NT Service [Resolved]

    I have created a service successfully and the executable I am
    binding to it is also compiled from VB. So, program "A" is the one
    creating the service and program "B" is the program that is run
    as a service. My issue is that program "A" always comes back
    with an error when I try to Start the service from the program.

    If I manually run the service it gives the error that "The program
    did not resopond in a timely fashion.

    What are the requirements for a program to run as a service? Am
    I missing a callback procedure or something in the service exe?

    Service program "B" seems to run though because it is outputing
    a textfile detecting the platform and version correctly. Nothing
    fancy. I want to add more , but I am not sure what is missing.

    Thanks for any input.
    Last edited by RobDog888; Jun 11th, 2004 at 12:37 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  2. #2
    Addicted Member
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    135
    As far as I know, Vbasic programs cannot be run as a service because it has something to do with the way it polls the operating system.

    I have seen some OCX controls that are for running your program as a service....

    Not sure if that helps....

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Yes, I have that control from M$ its the NTSRV.ocx control. I
    wanted to try to stay away from depending on it since M$ doesn't
    support it. Don't want to create any issues on our servers. So I
    created the service entirely with APIs. Not really too hard after
    you know how. The issue is that my program is not responding
    back to the Service Manager with a response of either successful
    start or failure to start within the 30 second time out.

    The reason for all of this is that I need to get a list of the Local
    Fixed Disks on a remote server that I have Domain Admins
    priviliages. Since that APIs to get the drives only works for the
    local system its being run from, if I was to run it from my
    workstation it will list my drives and not the target server drives.

    So, I created this service remotely on the target server and the
    exe that is bound to the service is copied over to list the drives.
    I also want to run a bat file from the service to get the
    defragmentation analysis of the server. I know how to do this
    that is why I need the list of drives. It also detects the platform
    and version to see if it is supported or not. Defrag.exe is only
    supported under Windows XP and Server 2003 and above.

    I can do all of these if only I can get the service to successfully
    start.

    Thanks for reading this looong explanation.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    *BUMP*
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Take a good look at FireDaemon:

    http://www.firedaemon.com/

  6. #6

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Thanks RhinoBull, but @$995 for the OEM commercial
    redistributable version, too much money.

    I need to find a solution to this issue soon. I need to be able to
    create a vb program that can be run as a service. I already have
    the other part finished where I create the service and bind an
    exe to the service. What do I need in the exe to communicate
    with the service manager to let it know that the service started
    or not. I keep getting the error that - "Could not start service on
    local computer. Error: 1053: The service did not respond to the
    start or control request in a timely fashion." But it actuall did start.
    I dont know if the sm closes the program because as of now it is
    only doing a small number of tasks and ending or if the sm is
    closing it.


    This is an example of a binded exe that I need to create.

    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

  8. #8

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    YES, this is exactly what I was missing! Thanks allot RhinoBull.
    I knew there was a procedure for handeling communications back
    to the service manager. Also, found the procedure for passing
    arguments to the service! Now I just need to incorporate it into
    my service program.
    Just a sample of what was missing...
    VB Code:
    1. Private Sub ServiceMain(ByVal dwArgc As Long, ByVal lpszArgv As Long)
    2.     ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS
    3.     ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP _
    4.                                     Or SERVICE_ACCEPT_SHUTDOWN
    5.     ServiceStatus.dwWin32ExitCode = 0&
    6.     ServiceStatus.dwServiceSpecificExitCode = 0&
    7.     ServiceStatus.dwCheckPoint = 0&
    8.     ServiceStatus.dwWaitHint = 0&
    9.     hServiceStatus = [color=red]RegisterServiceCtrlHandler[/color](Service_Name, _
    10.                            AddressOf Handler)
    11.     SetServiceState SERVICE_START_PENDING
    12.     ' Set hStartEvent. It unlocks main application thread
    13.     ' which allows to do some work in it
    14.     SetEvent hStartEvent
    15.     ' Wait until hStopEvent fires
    16.     WaitForSingleObject hStopEvent, INFINITE
    17. End Sub
    18.    
    19. ' The Handler sub processes commands from Service Dispatcher.
    20. ' It sets event hStopEvent when processes command
    21. ' SERVICE_CONTROL_STOP or SERVICE_CONTROL_SHUTDOWN.
    22. Private Sub [color=red]Handler[/color](ByVal fdwControl As Long)
    23.     Select Case fdwControl
    24.         Case SERVICE_CONTROL_SHUTDOWN, SERVICE_CONTROL_STOP
    25.             SetServiceState SERVICE_STOP_PENDING
    26.             SetEvent hStopPendingEvent
    27.         Case Else
    28.             SetServiceState
    29.     End Select
    30. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Sounds like a plan.

  10. #10

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    One other thing, the service program example contains a
    reference to a typelibrary file and some .odl files. I don't want to
    have to rely on these in my program. At initial look, it seems that
    they are just holding all the APs and type structures for simplicity.
    Does this look like a correct assumption to you too?

    Thanks
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width