Creating NT service with VB.... (Yes I looked at MS's example) 
Author Message
 Creating NT service with VB.... (Yes I looked at MS's example)

I read MS's example and have looked a several web sites.  I am using srvany
and yes, I read it's readme file also...  I have made the changes to the
registry.  I get the following error...

Could not start the <SERVICE NAME> on <\\COMPUTER NAME>.
Error 2410: An internal Windows NT error occured.

The event log shows it timing out after 120000 milliseconds......

I am trying to use the following .BAS that I found on the web, does it
matter that I have it set as a system account and want it to interact with
the desktop....  this is just to get it working.  I am trying to have it
load a form with a button??  Any and all ideas welcome.

Jon


domain.
' Routines for running an app as an NT service.
Public Const GWL_WNDPROC = (-4)
Public Const WM_ENDSESSION = &H16
Public Const WM_QUERYENDSESSION = &H11
Public WndProc As Long
Declare Function GetCurrentProcess Lib "kernel32" () As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal
lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam
As Long, ByVal lParam As Long) As Long
Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long,
ByVal uExitCode As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal
hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
' Call this routine to ensure app is not killed off by local user logoff
Public Sub Hook(Lwnd As Long)
Dim uProcess As Long
  WndProc = SetWindowLong(Lwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long
If uMsg = WM_QUERYENDSESSION Then
  WindowProc = True
  Exit Function
ElseIf uMsg = WM_ENDSESSION Then
  WindowProc = True
  Exit Function
End If
WindowProc = CallWindowProc(WndProc, hw, uMsg, wParam, lParam)

End Function
' Terminate an active NT service - only way to kill application'
Public Sub EndApp()
Dim uProcess As Long
  uProcess = GetCurrentProcess
  TerminateProcess uProcess, 0
End Sub



Sun, 01 Apr 2001 03:00:00 GMT  
 Creating NT service with VB.... (Yes I looked at MS's example)
I figured out my mistake......  Error in my registry entry..... I can spell.

Jon

Quote:

>I read MS's example and have looked a several web sites.  I am using srvany
>and yes, I read it's readme file also...  I have made the changes to the
>registry.  I get the following error...

>Could not start the <SERVICE NAME> on <\\COMPUTER NAME>.
>Error 2410: An internal Windows NT error occured.

>The event log shows it timing out after 120000 milliseconds......

>I am trying to use the following .BAS that I found on the web, does it
>matter that I have it set as a system account and want it to interact with
>the desktop....  this is just to get it working.  I am trying to have it
>load a form with a button??  Any and all ideas welcome.

>Jon


>domain.
>' Routines for running an app as an NT service.
>Public Const GWL_WNDPROC = (-4)
>Public Const WM_ENDSESSION = &H16
>Public Const WM_QUERYENDSESSION = &H11
>Public WndProc As Long
>Declare Function GetCurrentProcess Lib "kernel32" () As Long
>Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal
>lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam
>As Long, ByVal lParam As Long) As Long
>Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long,
>ByVal uExitCode As Long) As Long
>Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal
>hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
>' Call this routine to ensure app is not killed off by local user logoff
>Public Sub Hook(Lwnd As Long)
>Dim uProcess As Long
>  WndProc = SetWindowLong(Lwnd, GWL_WNDPROC, AddressOf WindowProc)
>End Sub
>Public Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal
>wParam As Long, ByVal lParam As Long) As Long
>If uMsg = WM_QUERYENDSESSION Then
>  WindowProc = True
>  Exit Function
>ElseIf uMsg = WM_ENDSESSION Then
>  WindowProc = True
>  Exit Function
>End If
>WindowProc = CallWindowProc(WndProc, hw, uMsg, wParam, lParam)

>End Function
>' Terminate an active NT service - only way to kill application'
>Public Sub EndApp()
>Dim uProcess As Long
>  uProcess = GetCurrentProcess
>  TerminateProcess uProcess, 0
>End Sub



Sun, 01 Apr 2001 03:00:00 GMT  
 Creating NT service with VB.... (Yes I looked at MS's example)

Quote:

>Dear all,

>  I am trying to start a service by using StartService in VB. I am having
>problems to pass a string or two integers to a service. Actually I can only
>pass one integer to a service. I tried to use double dimentional array
>without any sucess.

>BOOL StartServie(
>SC_HANDLE hServie,
>DWORD dwNumServiceArgs,
>LPCTSTR *lpServiceArgVectors //address of array of argument string pointers
>);

>Anybody has any suggestions? Thanks for your attention.

Here's the VB equivalent declaration of the StartService call:

Declare Function StartService Lib "advapi32.dll" _
        Alias "StartServiceA" (ByVal hService As Long, _
        ByVal dwNumServiceArgs As Long, _
        ByVal lpServiceArgVectors As Long) As Long

The first two arguments will be long integers.   An example call
would be:

     Dim argv(5) as string
                .
            .
                .   fill array with necessary arguments
        .   hService must be set to the handle of
        .   the desired service returned by
        .   OpenService or CreateService
        .
        .
     result = StartService(hService, Ubound(argv) + 1, argv(0) )


:)             aka Jack Voltz            :)  Web: www.ovnet.com/~voltz
:)      M  A  R  A  N  A  T  H  A  !     :)  Y2K: www.ovnet.com/~voltz/y2klinks.htm
:)    S i e m p r e  P o r   V i d a !   :)  
----------------------------------------------------------------------
Prolife: http://www.ovnet.com/~voltz/prolife.htm
Music:   http://www.ovnet.com/~voltz/music.htm



Tue, 17 Apr 2001 03:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Creating NT service with VB.... (Yes I looked at MS's example)

2. Creating NT service with VB.... (Yes I looked at MS's example)

3. NT Service: An OLE Control for Creating Windows NT Services in Visual Basic (MSDN article)

4. NT Service: An OLE Control for Creating Windows NT Services in Visual Basic (MSDN article)

5. NT Service: An OLE Control for Creating Windows NT Services in Visual Basic (MSDN article)

6. Created and installed VB.Net service but don't see it in services

7. looking for VB examples of setting the preinter settings - NT

8. Help with 'NT Service' VB Control

9. look if a nt service is runnning (window 2000 server), in vb net

10. Word Docs - Look for example to create them from VB.Net

11. Ole Directory Services (Active Directory Services) 1.1 - Has any body managed to use the VB examples

12. Need Help Creating NT Services with VB

 

 
Powered by phpBB® Forum Software