Login  
Search All Forums
Dart Home | PowerTCP Server for ActiveX | Custom Development Reply | PowerTCP Server for ActiveX Topics | Forums   
AuthorForum: PowerTCP Server for ActiveX
Topic: Service and Command Line
dan182

From: london, United Kingdom
Posts: 6
Member Since: 10/22/04
posted February 4, 2005 5:38 AM

I have an application that can be run both as a service or as a normal win32 app.

When the app starts it accepts
/Install - Installs
/Uninstall - Uninstalls
/? - Displays help
/App - Runs as an app

Now if no command is specified then it will issue the .Connect
Now everything works like a dream, but what now happens if the user the double clicks the exe because it attempts to connect and causes variours issues depending on whether or not it is installed.

So my question is how do i install the service so that it accepts command line args ??

Then the solution is simple

If Arg = Service then
 .Connect
Else
 RunAsApp
Endif

Thanks in advance

Dan
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted February 4, 2005 8:43 AM

Have you seen the example "Simple Service Demo" that gets installed with the product?
dan182

From: london, United Kingdom
Posts: 6
Member Since: 10/22/04
posted February 4, 2005 8:52 AM

yeah i did (unless there has been an update) - the problem still remains in that double clicking the exe launches it in service mode.

not to worry though i have done this
.Install
then modify reg key ImagePath value to = "C:\Myservice.exe /s"

then when it starts

if CommandLine = "s" then
 .Connect
else
 .Launch as app
endif

thx for the reply
Daniel
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted February 4, 2005 8:56 AM

That's a good tip. Thanks.
Any idea why the OS doesn't let specify a command line when you set up the service?
dan182

From: london, United Kingdom
Posts: 6
Member Since: 10/22/04
posted February 4, 2005 9:08 AM

the problem i had was not so much that the OS did not allow the specifying of a command line but that the method .INSTALL of the control did not give you the option to add a command line parameter.

the OS appears quite happy when you add it to the registry. i am pretty sure is all the OS does to launch the app would be cmd "ImagePath".

the scm however does not give a UI to modify the image path property.

the end solution being just to edit the key in code after issusing .INSTALL works easily enough. the other thing i like about this method now is that the double click launches as an app as you would expect.

there is one small danger though and that is if a bat file is created and they launch the app as an app but specify the switch /s which in turn now tells the app it is a service which then issues .Connect - problem.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted February 4, 2005 9:18 AM

You are using our service control, correct?
If so you should get an error event after about 20 secs. The code in the demo that handles this case is here:

Private SCMStop as Boolean

Private Sub Form_Load()
  SCMStop = False
  CheckCommandLine
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  If Not SCMStop Then
    Cancel = True
    MsgBox "You must use the Service Control Manager (SCM) to stop and start this app", vbCritical, APPNAME
  End If
End Sub

' Fires when the Service control manager reports an error
Private Sub Service1_Error(ByVal Number As DartServiceCtl.ErrorConstants, ByVal Description As String)
  ' These two errors indicate that the Service Control manager
  ' was unable to communicate with this app. This is usually
  ' caused by attempting to run the program without /a argument
  ' In that case, this app will not be visible and if it is not killed
  ' here, will never go away
  If Number = serviceFailedConnect Or Number = serviceUnsupported Then
    MsgBox "Service failed to connect. This program is meant to be started and stopped via the NT/2000/XP Service Control Manager", vbCritical, "Service Error"
    SCMStop = True
    End
  Else
    ' Write the error information to the event log
    Service1.Log serviceError, serviceErrorEvent, Description
  End If
End Sub
dan182

From: london, United Kingdom
Posts: 6
Member Since: 10/22/04
posted February 4, 2005 9:25 AM

yeah i have all of that already but it does not produce an error and here is why

1. Create a service
2. Install it.
3. Double click the exe.

Now you will not be able to close the exe because

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
 If Not SCMStop Then
  Cancel = True
  MsgBox "You must use the Service Control Manager (SCM) to stop and start this app", vbCritical, APPNAME
 End If
End Sub

the reason the error does not trip is because it can connect because it is installed.

either way i am not worried i have a solution which is perfect for me.


daniel
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted February 4, 2005 9:30 AM

Ok, thanks. Just wanted to make sure that this topic as many keywords as possible so other people will find it later via searching.

:>)

Reply | PowerTCP Server for ActiveX Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX