?
Solved

TService::ParamCount is always zero?

Posted on 2013-06-16
2
Medium Priority
?
499 Views
Last Modified: 2013-06-17
I have written a service application in Borland C++ builder 5 and wish to pass a parameter on the command line when the service application is installed (not when it is started). I have tested this by entering the following onstallation command :
 myservice /install  param1

The following code is my constructor for the service application and always indicates that the ParamCount has a value of zero, even when passing a parameter after the /install parameter when installing the service.

Is there any way to pass a parameter on the command line when installing a service application ?

__fastcall T_2WSOPDSService1::T_2WSOPDSService1(TComponent* Owner)
      : TService(Owner)
{
    int pcount;
    AnsiString s;

    pcount = ParamCount;
    s.sprintf("ParamCount on installation was %d",pcount);
    LogMessage(s,EVENTLOG_INFORMATION_TYPE,0,0);


    dbsconnected = false;
    update = NULL;
    return;
}
0
Comment
Question by:alcindor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 2000 total points
ID: 39251995
Just a small note. The install parameter will be processed by the application when it runs in "Application" mode, not as a service mode. It will be handled by your "main" entry point.
You would probably need to provide us with more code in order to help. Please upload here the main program entry point where you handle the "/install" command line parameter
0
 
LVL 2

Author Comment

by:alcindor
ID: 39253037
I don't handle the "/install" command line parameter myself, this is handled by a built-in handler provided by the Borland compiler when making a service application.
However, I managed to extract the command line parameters from the command line by using the code in WinMain as follows. Thanks for your help.

AnsiString s_main; // added this variable to hold the command line
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR s, int)
{

try
{
                   s_main = s; // s_main is referenced in the service application constuctor
      Application->Initialize();
      Application->CreateForm(__classid(T_2WSOPDSService1), &_2WSOPDSService1);
                  Application->Run();
}
catch (Exception &exception)
{
      Sysutils::ShowException(&exception, Sysutils::ExceptAddr());
}
      return 0;
}
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question