Results 1 to 14 of 14

Thread: Run application as SERVICE?

  1. #1

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482

    Exclamation Run application as SERVICE?

    Hi all,
    I have heard this words lot of times here..
    "Make application as SERVICE" or
    "Run the application as a SERVICE"
    What does it means? How it can be done? And can anyone tell me its benifits and drawbacks?
    Thanks in advance...
    Anita.
    Can't imagine life without VB
    (Various Boyfriends)

  2. #2
    Lively Member
    Join Date
    Mar 2002
    Posts
    75
    not sure if there is any difference, but stuff like norton anti virus run as service..

  3. #3
    Hyperactive Member Dinz's Avatar
    Join Date
    Jan 2002
    Posts
    359
    ummmmmm..........i believe somthing to do with server of Client-Server...I am not sure
    !!!NobodyisPerfect......IamNOBODY!!!
    How's your wife and my kids?.....

    Never argue with an idiot. They drag you down to their level then beat you with experience!

    Child says : Mummy mummy, can i play with grandpa ?
    Mum says : NO, you have already dug him up twice.

    Galahtec The VB Forum

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    -= a peet post =-

  5. #5

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482
    Originally posted by Dinz
    ummmmmm..........i believe somthing to do with server of Client-Server...I am not sure
    Really?
    Is it related with client-server?
    can anyone tell?
    Anita
    Can't imagine life without VB
    (Various Boyfriends)

  6. #6
    Junior Member ravi_sekhar's Avatar
    Join Date
    Jan 2002
    Posts
    31

    may be this is helpful

    Hi anita,
    When you go through Start->Settings-> ControlPanel -> Services. You can see a list of services running on your system and their status(Whether running or stopped) and startup(whether started automatically or manually). If iam not wrong you want to make your Vb application(not various boy friends) to be added to this list.
    Cheer's,
    Ravi.

  7. #7

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482

    Re: may be this is helpful

    Originally posted by ravi_sekhar
    Hi anita,
    When you go through Start->Settings-> ControlPanel -> Services. You can see a list of services running on your system and their status(Whether running or stopped) and startup(whether started automatically or manually). If iam not wrong you want to make your Vb application(not various boy friends) to be added to this list.
    I havent got anything as "services" in Start->Settings-> ControlPanel
    do u mean "task manager"
    Anita...
    Can't imagine life without VB
    (Various Boyfriends)

  8. #8
    Junior Member ravi_sekhar's Avatar
    Join Date
    Jan 2002
    Posts
    31

    No No

    No baby, you are wrong. Search cooly in your control panel. It is there in win2000 and winnt. what OS do you use?? I am not getting your problem exactly.......
    Cheer's,
    Ravi.

  9. #9
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    This helped me make my first service.
    http://www.vbforums.com/showthread.p...ices+are+tough

    Its sorta a template.

    Check out the down load

    Seahag

  10. #10

    Thread Starter
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482

    Re: No No

    Originally posted by ravi_sekhar
    No baby, you are wrong. Search cooly in your control panel. It is there in win2000 and winnt. what OS do you use?? I am not getting your problem exactly.......
    Oh, there is nothing like "services" in control pannel..
    i'm using win2000
    Can't imagine life without VB
    (Various Boyfriends)

  11. #11
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Well I'm pretty sure that you should be able to find this key in your registry at least.
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices

    In my registry that's where my ZoneAlarm TrueVector entry sits. and unless I'm totally off on this, the RunServices key has loading priority over the Run key which will make other software load at startup. Understandably this would be crucial requirement to any firewall or Anti Virus software.
    The firewall has to be able to stop any Trojans or virus from attempting to establish a connection on execution. Obviously it ain't loaded when that happens it wouldn’t help you much
    Any way you probably know all this but If you are just wanting to add your app to this list, just find any code on this forum that will let you create a key in the registry and modify it to point to this key instead.

    Here's what the registry entry for TrueVector looks like on my Win98 system BTW:
    "C:\WINDOWS\SYSTEM\ZONELABS\VSMON.EXE -service"

    If you were reffering to a way to hide your app from task manager's list by running it as a service, this might be what you need then..

    VB Code:
    1. Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    2. Public Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessId As Long, ByVal dwType As Long) As Long
    3. Public Const RSP_SIMPLE_SERVICE = 1
    4. Public Const RSP_UNREGISTER_SERVICE = 0
    5.  
    6. Public Sub MakeMeService()
    7. 'To hide your application from the Task Manager
    8. Dim pid As Long
    9. Dim regserv As Long
    10.  pid = GetCurrentProcessId()
    11.  regserv = RegisterServiceProcess(pid, RSP_SIMPLE_SERVICE)
    12. End Sub
    13.  
    14. Public Sub UnMakeMeService()
    15. 'To restore your application to the Task Manager
    16. Dim pid As Long
    17. Dim regserv As Long
    18.  pid = GetCurrentProcessId()
    19.  regserv = RegisterServiceProcess(pid, RSP_UNREGISTER_SERVICE)
    20. End Sub
    hope this helps!

  12. #12
    Addicted Member
    Join Date
    Dec 2001
    Location
    MD
    Posts
    182
    Try opening "Administrative tools" under "Control Panel", U may find Services there.

  13. #13
    Frenzied Member oh1mie's Avatar
    Join Date
    Sep 2001
    Location
    Finland
    Posts
    1,043
    Here is some more tools for you

    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SERVICE_WIN32_OWN_PROCESS = &H10&
    4. Private Const SERVICE_WIN32_SHARE_PROCESS = &H20&
    5. Private Const SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS + _
    6.                               SERVICE_WIN32_SHARE_PROCESS
    7.  
    8. Private Const SERVICE_ACCEPT_STOP = &H1
    9. Private Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2
    10. Private Const SERVICE_ACCEPT_SHUTDOWN = &H4
    11.  
    12. Private Const SC_MANAGER_CONNECT = &H1
    13. Private Const SC_MANAGER_CREATE_SERVICE = &H2
    14. Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4
    15. Private Const SC_MANAGER_LOCK = &H8
    16. Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10
    17. Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
    18.  
    19. Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
    20. Private Const SERVICE_QUERY_CONFIG = &H1
    21. Private Const SERVICE_CHANGE_CONFIG = &H2
    22. Private Const SERVICE_QUERY_STATUS = &H4
    23. Private Const SERVICE_ENUMERATE_DEPENDENTS = &H8
    24. Private Const SERVICE_START = &H10
    25. Private Const SERVICE_STOP = &H20
    26. Private Const SERVICE_PAUSE_CONTINUE = &H40
    27. Private Const SERVICE_INTERROGATE = &H80
    28. Private Const SERVICE_USER_DEFINED_CONTROL = &H100
    29. Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
    30.                                     SERVICE_QUERY_CONFIG Or _
    31.                                     SERVICE_CHANGE_CONFIG Or _
    32.                                     SERVICE_QUERY_STATUS Or _
    33.                                     SERVICE_ENUMERATE_DEPENDENTS Or _
    34.                                     SERVICE_START Or _
    35.                                     SERVICE_STOP Or _
    36.                                     SERVICE_PAUSE_CONTINUE Or _
    37.                                     SERVICE_INTERROGATE Or _
    38.                                      SERVICE_USER_DEFINED_CONTROL)
    39.  
    40. Private Const SERVICE_DEMAND_START As Long = &H3
    41. Private Const SERVICE_ERROR_NORMAL As Long = &H1
    42.  
    43. ' Private Enum SERVICE_CONTROL
    44. Private Const SERVICE_CONTROL_STOP = &H1
    45. Private Const SERVICE_CONTROL_PAUSE = &H2
    46. Private Const SERVICE_CONTROL_CONTINUE = &H3
    47. Private Const SERVICE_CONTROL_INTERROGATE = &H4
    48. Private Const SERVICE_CONTROL_SHUTDOWN = &H5
    49. ' End Enum
    50.  
    51. ' Private Enum SERVICE_STATE
    52. Private Const SERVICE_STOPPED = &H1
    53. Private Const SERVICE_START_PENDING = &H2
    54. Private Const SERVICE_STOP_PENDING = &H3
    55. Private Const SERVICE_RUNNING = &H4
    56. Private Const SERVICE_CONTINUE_PENDING = &H5
    57. Private Const SERVICE_PAUSE_PENDING = &H6
    58. Private Const SERVICE_PAUSED = &H7
    59. ' End Enum
    60.  
    61. Private Type SERVICE_TABLE_ENTRY
    62.    lpServiceName     As String
    63.    lpServiceProc     As Long
    64.    lpServiceNameNull As Long
    65.    lpServiceProcNull As Long
    66. End Type
    67.  
    68. Private Type SERVICE_STATUS
    69.    dwServiceType             As Long
    70.    dwCurrentState            As Long
    71.    dwControlsAccepted        As Long
    72.    dwWin32ExitCode           As Long
    73.    dwServiceSpecificExitCode As Long
    74.    dwCheckPoint              As Long
    75.    dwWaitHint                As Long
    76. End Type
    77.  
    78. Private Declare Function StartServiceCtrlDispatcher Lib "advapi32.dll" Alias "StartServiceCtrlDispatcherA" (lpServiceStartTable As SERVICE_TABLE_ENTRY) As Long
    79. Private Declare Function RegisterServiceCtrlHandler Lib "advapi32.dll" Alias "RegisterServiceCtrlHandlerA" (ByVal lpServiceName As String, ByVal lpHandlerProc As Long) As Long
    80. Private Declare Function SetServiceStatus Lib "advapi32.dll" (ByVal hServiceStatus As Long, lpServiceStatus As SERVICE_STATUS) As Long
    81. Private Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
    82. Private Declare Function CreateService Lib "advapi32.dll" Alias "CreateServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal lpDisplayName As String, ByVal dwDesiredAccess As Long, ByVal dwServiceType As Long, ByVal dwStartType As Long, ByVal dwErrorControl As Long, ByVal lpBinaryPathName As String, ByVal lpLoadOrderGroup As String, ByVal lpdwTagId As String, ByVal lpDependencies As String, ByVal lp As String, ByVal lpPassword As String) As Long
    83. Private Declare Function DeleteService Lib "advapi32.dll" (ByVal hService As Long) As Long
    84. Declare Function CloseServiceHandle _
    85.     Lib "advapi32.dll" (ByVal hSCObject As Long) As Long
    86. Declare Function OpenService _
    87.     Lib "advapi32.dll" Alias "OpenServiceA" _
    88.     (ByVal hSCManager As Long, ByVal lpServiceName As String, _
    89.     ByVal dwDesiredAccess As Long) As Long
    90.  
    91. '** Change SERVICE_NAME as needed
    92. Private Const SERVICE_NAME As String = "MyService"
    93.  
    94. Private hServiceStatus As Long
    95. Private ServiceStatus  As SERVICE_STATUS
    96. Public Sub Main()
    97.      
    98.       Dim hSCManager As Long
    99.       Dim hService As Long
    100.       Dim ServiceTableEntry As SERVICE_TABLE_ENTRY
    101.       Dim b As Boolean
    102.       Dim cmd As String
    103.  
    104.       cmd = Trim(LCase(Command()))
    105.       Select Case cmd
    106.          Case "install"                      'Install service on machine
    107.             hSCManager = OpenSCManager(vbNullString, vbNullString, _
    108.                          SC_MANAGER_CREATE_SERVICE)
    109.             hService = CreateService(hSCManager, SERVICE_NAME, _
    110.                        SERVICE_NAME, SERVICE_ALL_ACCESS, _
    111.                        SERVICE_WIN32_OWN_PROCESS, _
    112.                        SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, _
    113.                        App.Path & "\" & App.EXEName, vbNullString, _
    114.                        vbNullString, vbNullString, vbNullString, _
    115.                        vbNullString)
    116.             CloseServiceHandle hService
    117.             CloseServiceHandle hSCManager
    118.          Case "uninstall"                   'Remove service from machine
    119.             hSCManager = OpenSCManager(vbNullString, vbNullString, _
    120.                          SC_MANAGER_CREATE_SERVICE)
    121.             hService = OpenService(hSCManager, SERVICE_NAME, _
    122.                        SERVICE_ALL_ACCESS)
    123.             DeleteService hService
    124.             CloseServiceHandle hService
    125.             CloseServiceHandle hSCManager
    126.          Case Else                                    'Start the service
    127.             ServiceTableEntry.lpServiceName = SERVICE_NAME
    128.             ServiceTableEntry.lpServiceProc = FncPtr(AddressOf ServiceMain)
    129.             b = StartServiceCtrlDispatcher(ServiceTableEntry)
    130.       End Select
    131.    
    132.    End Sub
    133. Public Sub ServiceMain(ByVal dwArgc As Long, ByVal lpszArgv As Long)
    134.      
    135.       Dim b As Boolean
    136.  
    137.       'Set initial state
    138.       ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS
    139.       ServiceStatus.dwCurrentState = SERVICE_START_PENDING
    140.       ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP _
    141.                                       Or SERVICE_ACCEPT_PAUSE_CONTINUE _
    142.                                       Or SERVICE_ACCEPT_SHUTDOWN
    143.       ServiceStatus.dwWin32ExitCode = 0
    144.       ServiceStatus.dwServiceSpecificExitCode = 0
    145.       ServiceStatus.dwCheckPoint = 0
    146.       ServiceStatus.dwWaitHint = 0
    147.  
    148.       hServiceStatus = RegisterServiceCtrlHandler(SERVICE_NAME, AddressOf Handler)
    149.       ServiceStatus.dwCurrentState = SERVICE_START_PENDING
    150.       b = SetServiceStatus(hServiceStatus, ServiceStatus)
    151.  
    152.       '** Do Initialization Here
    153.  
    154.       ServiceStatus.dwCurrentState = SERVICE_RUNNING
    155.       b = SetServiceStatus(hServiceStatus, ServiceStatus)
    156.  
    157.       '** Perform tasks -- if none exit
    158.  
    159.       ''** If an error occurs, the following should be used for shutting
    160.       ''** down:
    161.       ''   SetServerStatus SERVICE_STOP_PENDING
    162.       ''   Clean up
    163.       ''   SetServerStatus SERVICE_STOPPED
    164.  
    165. End Sub
    166. Public Sub Handler(ByVal fdwControl As Long)
    167.      
    168.       Dim b As Boolean
    169.  
    170.       Select Case fdwControl
    171.          Case SERVICE_CONTROL_PAUSE
    172.             '** Do whatever it takes to pause here.
    173.             ServiceStatus.dwCurrentState = SERVICE_PAUSED
    174.          Case SERVICE_CONTROL_CONTINUE
    175.             '** Do whatever it takes to continue here.
    176.             ServiceStatus.dwCurrentState = SERVICE_RUNNING
    177.          Case SERVICE_CONTROL_STOP
    178.             ServiceStatus.dwWin32ExitCode = 0
    179.             ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING
    180.             ServiceStatus.dwCheckPoint = 0
    181.             ServiceStatus.dwWaitHint = 0     'Might want a time estimate
    182.             b = SetServiceStatus(hServiceStatus, ServiceStatus)
    183.             '** Do whatever it takes to stop here.
    184.             ServiceStatus.dwCurrentState = SERVICE_STOPPED
    185.          Case SERVICE_CONTROL_INTERROGATE
    186.             'Fall through to send current status.
    187.          Case Else
    188.       End Select
    189.       'Send current status.
    190.       b = SetServiceStatus(hServiceStatus, ServiceStatus)
    191. End Sub
    192. Public Function FncPtr(ByVal fnp As Long) As Long
    193.    FncPtr = fnp
    194. End Function
    oh1mie/Vic


  14. #14
    Member
    Join Date
    Apr 2002
    Posts
    42
    Hi,

    Benefit is no need to start manually.When windows
    starts , it starts atomatically.
    In control panel u can find serives on win2k and NT.

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