|
-
Oct 5th, 2001, 05:27 AM
#1
Thread Starter
Fanatic Member
How do i create a "service"?
I want to make an application that runs as a service. The application has no user interface. I want to create an MMC snap-in to set and change variables within this application. I might also want to create other applications that can link to that same instance of the "service" application to set and manipulate variables.
How could this be done? ActiveX.exe's or normal .exe with .dll?
How then would i specify in another app, that it must connect to that instance of the service, and not create a new one.
-
Oct 5th, 2001, 06:32 AM
#2
Fanatic Member
You might want to think about using another language.
You can write a service in VB, but it is not ideal.
Services do not always have access to the display, and since VB defaults to the display for an untrapped (or untrappable) error, you can have a problem.
You basically have to trap every possible error and write to a log rather than to the display.
We started trying to write a service in VB last year, but quickly gave up and did it in C instead.
If you try it, here's a good place to start:
http://vbwire.com/advanced/howto/service.asp
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Oct 5th, 2001, 06:49 AM
#3
Thread Starter
Fanatic Member
Ok. Is it possible though to have other applications link dirrectly to a running instance of my app or object. If so, how do i go about this?
-
Oct 5th, 2001, 10:20 AM
#4
Fanatic Member
Yes, I know it is, but I'm not sure exactly how.
I guess you need to find the handle of the application and then send it a message?
Perhaps somebody smarter than me can help? Otherwise I'll give it a try over the weekend and see how it goes.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Oct 6th, 2001, 05:13 AM
#5
Hyperactive Member
I don't know if this is of any use, but I use this code to register a VB app as a service to hide it from CTRL-ALT-DEL. The only problem is that the API is unsupported under WinNT. Call RegisterAsService to hide it, and UnRegisterAsService to show it again.
VB Code:
' Declarations and constants to hide from CTRL-ALT-DEL list
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long
Private Const RSP_UNREGISTER_SERVICE = 0
Private Const RSP_SIMPLE_SERVICE = 1
Private Sub RegisterAsService()
' Hide program from CTRL-ALT-DEL list by registering it as a service
Dim lProcId As Long
Dim lReturn As Long
lProcId = GetCurrentProcessId()
lReturn = RegisterServiceProcess(lProcId, RSP_SIMPLE_SERVICE)
End Sub
Private Sub UnRegisterAsService()
' Restore program to CTRL-ALT-DEL list by unregistering it as a service
Dim lProcId As Long
Dim lReturn As Long
lProcId = GetCurrentProcessId()
lReturn = RegisterServiceProcess(lProcId, RSP_UNREGISTER_SERVICE)
End Sub
-
Oct 6th, 2001, 09:47 AM
#6
Thread Starter
Fanatic Member
thanx rudgej.
Unfortunately, the standard is NT. In actual fact it will be running under NT Server.
I don't think it is all too possible to accomplish a "service" application in VB, like BrianHawley says. I will work around it, and definately start learning C!
How does a program like Excel achieve the linking though. I have been able to use the GetObject function to get the already running instance of Ecel. Does anyone know a VB way of doing the same thing?
-
Nov 3rd, 2004, 02:39 AM
#7
-
Nov 3rd, 2004, 12:21 PM
#8
Yes it is possible under VB to create and register a vb program as
a NT Service. Look here for the code to create the service exe and
here to register and create the service out of your exe.
Its a two step process. You need to create the exe that will
interact with the Service Manager and another step to actually
create the NT Service and register the exe to be associated with
the service.
HTH
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
|