Results 1 to 10 of 10

Thread: How can i Open a regeister an application as a Service.

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    58

    How can i Open a regeister an application as a Service.

    What i mean is how can i make VB open an .exe file and tell it to be a Service.

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: How can i Open a regeister an application as a Service.

    Try searching for the RegisterServiceProcess API.


    Has someone helped you? Then you can Rate their helpful post.

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

    Re: How can i Open a regeister an application as a Service.

    You will also need OpenSCManager, StartService, StopService, and CreateService if this is going to
    be on an NT platform OS.
    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
    Member
    Join Date
    Jan 2005
    Posts
    58

    Re: How can i Open a regeister an application as a Service.

    hmm i can't seem to grasp this.. Can someone make me a Demo using Notepad.exe Thankz//

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

    Re: How can i Open a regeister an application as a Service.

    Ok, but is this for Windows 95/98 or NT 4.0+ ?

    Also, local computer only or remote manipulation too?
    If its for remote manipulation then its allot of code, even for a small demo
    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

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    58

    Re: How can i Open a regeister an application as a Service.

    ITs for WIndows XP. ANd what do you mean Remote and Local?

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

    Re: How can i Open a regeister an application as a Service.

    Remote would be to install/control a service on another computer on your network and local is your
    workstation (xp) that your developing on, so to speak.

    Since its NT based and sounds like it is going to be local then I would suggest using the unsupported
    ntsvc.ocx control from M$.

    I will put together something now.

    Be back.
    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

  8. #8

  9. #9

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    58

    Re: How can i Open a regeister an application as a Service.

    Ohh thankz alot RobDog888.

    Can you make that demo open notepad.exe as a service thankz.
    Last edited by Davoay; Feb 26th, 2005 at 08:07 PM.

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

    Re: How can i Open a regeister an application as a Service.

    Here is the demo. It writes to a text file every 5 seconds. It works except for the stop command?
    Also, previous instance needs to be added, but the details you can handle.

    VB Code:
    1. Option Explicit
    2. 'Add Microsoft NT Service Control to your toolbox and add to your form.
    3. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    4. Private iKount As Integer
    5.  
    6. Private Sub Form_Load()
    7.     On Error GoTo Err_Load
    8.    
    9.     Dim strDisplayName As String
    10.     Dim bStarted As Boolean
    11.    
    12.     NTService1.DisplayName = "RobDog888 - Service Demo"
    13.     NTService1.ServiceName = "RobDog888 - Service Demo"
    14.     strDisplayName = NTService1.DisplayName
    15.     If Command = "-install" Then
    16.         'enable interaction with desktop
    17.         NTService1.Interactive = True
    18.         If NTService1.Install Then
    19.             Call NTService1.SaveSetting("Parameters", "TimerInterval", "5000")
    20.             Call NTService1.SaveSetting("Parameters", "Path", "C:\Test_Service.txt")
    21.             MsgBox strDisplayName & " installed & started successfully"
    22.         Else
    23.             MsgBox strDisplayName & " failed to install"
    24.         End If
    25.         Timer1.Interval = CInt(NTService1.GetSetting("Parameters", "TimerInterval", ""))
    26.         frmMain.Visible = False
    27.         NTService1.ControlsAccepted = svcCtrlPauseContinue
    28.         NTService1.StartService
    29.     ElseIf Command = "-uninstall" Then
    30.         Timer1.Enabled = False
    31.         If NTService1.Uninstall Then
    32.             MsgBox strDisplayName & " uninstalled successfully"
    33.         Else
    34.             MsgBox strDisplayName & " failed to uninstall"
    35.         End If
    36.         Unload Me
    37.         End
    38.     ElseIf Command = "-start" Then
    39.         NTService1.Interactive = True
    40.         If NTService1.Running = True Then
    41.             'do nothing since already running
    42.             MsgBox "Already running!", vbOKOnly + vbExclamation, App.ProductName
    43.             Unload Me
    44.             End
    45.         Else
    46.             'start it
    47.             If NTService1.StartService Then
    48.                 Call NTService1.SaveSetting("Parameters", "TimerInterval", "5000")
    49.                 Call NTService1.SaveSetting("Parameters", "Path", "C:\Test_Service.txt")
    50.                 MsgBox strDisplayName & " started successfully"
    51.             Else
    52.                 MsgBox strDisplayName & " failed to start"
    53.             End If
    54.             Timer1.Interval = CInt(NTService1.GetSetting("Parameters", "TimerInterval", ""))
    55.             Timer1.Enabled = True
    56.             frmMain.Visible = False
    57.             NTService1.ControlsAccepted = svcCtrlPauseContinue
    58.         End If
    59.     ElseIf Command = "-stop" Then
    60.         Timer1.Enabled = False
    61.         NTService1.StopService
    62.         MsgBox strDisplayName & " stopped successfully"
    63.         Unload Me
    64.         End
    65.     ElseIf Command = "-debug" Then
    66.         NTService1.Debug = True
    67.     ElseIf Command <> "" Then
    68.         MsgBox "Invalid command option"
    69.         Unload Me
    70.         End
    71.     Else
    72.         MsgBox "Invalid command option"
    73.         Unload Me
    74.         End
    75.     End If
    76.     Call NTService1.LogEvent(svcMessageInfo, svcEventInformation, "[" & Command & "]")
    77.     Exit Sub
    78.    
    79. Err_Load:
    80.     Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
    81.     Unload Me
    82.     End
    83. End Sub
    84.  
    85. Private Sub NTService1_Continue(Success As Boolean)
    86.     On Error GoTo Err_Continue
    87.     Timer1.Enabled = True
    88.     Success = True
    89.     Call NTService1.LogEvent(svcEventInformation, svcMessageInfo, "Service continued")
    90.     Exit Sub
    91. Err_Continue:
    92.     Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
    93. End Sub
    94.  
    95. Private Sub NTService1_Pause(Success As Boolean)
    96.     On Error GoTo Err_Pause
    97.     Timer1.Enabled = False
    98.     Call NTService1.LogEvent(svcEventError, svcMessageError, "Service paused")
    99.     Success = True
    100.     Exit Sub
    101. Err_Pause:
    102.     Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
    103. End Sub
    104.  
    105. Private Sub NTService1_Start(Success As Boolean)
    106.     On Error GoTo Err_Start
    107.     Call NTService1.LogEvent(svcEventError, svcMessageError, "Service started")
    108.     Success = True
    109.     Exit Sub
    110. Err_Start:
    111.     Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
    112. End Sub
    113.  
    114. Private Sub NTService1_Stop()
    115.     On Error GoTo Err_Stop
    116.     Timer1.Enabled = False
    117.     End
    118. Err_Stop:
    119.     Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
    120. End Sub
    121.  
    122. Private Sub Timer1_Timer()
    123.     On Error GoTo Err_Timer
    124.     Dim sComputerName As String
    125.     Dim bSubSuccess As Boolean
    126.     bSubSuccess = WhatIsComputerName(sComputerName)
    127.     If bSubSuccess = False Then
    128.         sComputerName = "Error [" & Err.Number & " - " & Err.Description & "]"
    129.     Else
    130.         Open "C:\Test_Service.txt" For Append As #1
    131.             Print #1, "Machine name: " & sComputerName & " - " & Right("0000" & CStr(iKount), 4)
    132.             iKount = iKount + 1
    133.         Close #1
    134.     End If
    135.     Exit Sub
    136. Err_Timer:
    137.     Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
    138. End Sub
    139.  
    140. Private Function WhatIsComputerName(ByRef sName As String) As Boolean
    141.     On Error GoTo No_Bugs
    142.     Dim strString As String
    143.     strString = String(255, Chr$(0))
    144.     GetComputerName strString, 255
    145.     strString = Left$(strString, InStr(1, strString, Chr$(0)))
    146.     sName = Left(strString, Len(strString) - 1)
    147.     WhatIsComputerName = True
    148.     Exit Function
    149. No_Bugs:
    150.     WhatIsComputerName = False
    151. End Function
    Attached Files Attached Files
    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