Feb 26th, 2005, 03:20 PM
#1
Thread Starter
Member
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.
Feb 26th, 2005, 04:14 PM
#2
Feb 26th, 2005, 04:16 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Feb 26th, 2005, 05:26 PM
#4
Thread Starter
Member
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//
Feb 26th, 2005, 05:32 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Feb 26th, 2005, 06:02 PM
#6
Thread Starter
Member
Re: How can i Open a regeister an application as a Service.
ITs for WIndows XP. ANd what do you mean Remote and Local?
Feb 26th, 2005, 07:22 PM
#7
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Feb 26th, 2005, 07:28 PM
#8
Re: How can i Open a regeister an application as a Service.
The following link may be of some help:
http://www.smsoft.ru/en/ntservice.htm
Feb 26th, 2005, 07:53 PM
#9
Thread Starter
Member
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 .
Feb 26th, 2005, 10:44 PM
#10
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:
Option Explicit
'Add Microsoft NT Service Control to your toolbox and add to your form.
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private iKount As Integer
Private Sub Form_Load()
On Error GoTo Err_Load
Dim strDisplayName As String
Dim bStarted As Boolean
NTService1.DisplayName = "RobDog888 - Service Demo"
NTService1.ServiceName = "RobDog888 - Service Demo"
strDisplayName = NTService1.DisplayName
If Command = "-install" Then
'enable interaction with desktop
NTService1.Interactive = True
If NTService1.Install Then
Call NTService1.SaveSetting("Parameters", "TimerInterval", "5000")
Call NTService1.SaveSetting("Parameters", "Path", "C:\Test_Service.txt")
MsgBox strDisplayName & " installed & started successfully"
Else
MsgBox strDisplayName & " failed to install"
End If
Timer1.Interval = CInt(NTService1.GetSetting("Parameters", "TimerInterval", ""))
frmMain.Visible = False
NTService1.ControlsAccepted = svcCtrlPauseContinue
NTService1.StartService
ElseIf Command = "-uninstall" Then
Timer1.Enabled = False
If NTService1.Uninstall Then
MsgBox strDisplayName & " uninstalled successfully"
Else
MsgBox strDisplayName & " failed to uninstall"
End If
Unload Me
End
ElseIf Command = "-start" Then
NTService1.Interactive = True
If NTService1.Running = True Then
'do nothing since already running
MsgBox "Already running!", vbOKOnly + vbExclamation, App.ProductName
Unload Me
End
Else
'start it
If NTService1.StartService Then
Call NTService1.SaveSetting("Parameters", "TimerInterval", "5000")
Call NTService1.SaveSetting("Parameters", "Path", "C:\Test_Service.txt")
MsgBox strDisplayName & " started successfully"
Else
MsgBox strDisplayName & " failed to start"
End If
Timer1.Interval = CInt(NTService1.GetSetting("Parameters", "TimerInterval", ""))
Timer1.Enabled = True
frmMain.Visible = False
NTService1.ControlsAccepted = svcCtrlPauseContinue
End If
ElseIf Command = "-stop" Then
Timer1.Enabled = False
NTService1.StopService
MsgBox strDisplayName & " stopped successfully"
Unload Me
End
ElseIf Command = "-debug" Then
NTService1.Debug = True
ElseIf Command <> "" Then
MsgBox "Invalid command option"
Unload Me
End
Else
MsgBox "Invalid command option"
Unload Me
End
End If
Call NTService1.LogEvent(svcMessageInfo, svcEventInformation, "[" & Command & "]")
Exit Sub
Err_Load:
Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
Unload Me
End
End Sub
Private Sub NTService1_Continue(Success As Boolean)
On Error GoTo Err_Continue
Timer1.Enabled = True
Success = True
Call NTService1.LogEvent(svcEventInformation, svcMessageInfo, "Service continued")
Exit Sub
Err_Continue:
Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub
Private Sub NTService1_Pause(Success As Boolean)
On Error GoTo Err_Pause
Timer1.Enabled = False
Call NTService1.LogEvent(svcEventError, svcMessageError, "Service paused")
Success = True
Exit Sub
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
Call NTService1.LogEvent(svcEventError, svcMessageError, "Service started")
Success = True
Exit Sub
Err_Start:
Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub
Private Sub NTService1_Stop()
On Error GoTo Err_Stop
Timer1.Enabled = False
End
Err_Stop:
Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub
Private Sub Timer1_Timer()
On Error GoTo Err_Timer
Dim sComputerName As String
Dim bSubSuccess As Boolean
bSubSuccess = WhatIsComputerName(sComputerName)
If bSubSuccess = False Then
sComputerName = "Error [" & Err.Number & " - " & Err.Description & "]"
Else
Open "C:\Test_Service.txt" For Append As #1
Print #1, "Machine name: " & sComputerName & " - " & Right("0000" & CStr(iKount), 4)
iKount = iKount + 1
Close #1
End If
Exit Sub
Err_Timer:
Call NTService1.LogEvent(svcMessageError, svcEventError, "[" & Err.Number & "] " & Err.Description)
End Sub
Private Function WhatIsComputerName(ByRef sName As String) As Boolean
On Error GoTo No_Bugs
Dim strString As String
strString = String(255, Chr$(0))
GetComputerName strString, 255
strString = Left$(strString, InStr(1, strString, Chr$(0)))
sName = Left(strString, Len(strString) - 1)
WhatIsComputerName = True
Exit Function
No_Bugs:
WhatIsComputerName = False
End Function
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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
Forum Rules
Click Here to Expand Forum to Full Width