Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
7
Erster Beitrag:
vor 2 Jahren, 3 Monaten
Letzter Beitrag:
vor 2 Jahren, 3 Monaten
Beteiligte Autoren:
Arekusei Timakobu, Stewart Crisler, CCC2, Fabrice Harari

Window Service and CommandLine

Startbeitrag von Arekusei Timakobu am 09.03.2016 09:54

I have a Windows service. I need to run it (sometimes) in debug mode. I know I can set command line parameters in Service properties. I use this code in Service:

IF CommandLine(2) = "-d" THEN
// activate debug mode
END


But unfortunately the debug mode is not activated. I do some testing and write content of CommandLine(),CommandLine(1),CommandLine(2) in EventLog and I saw complete filename for service executable in cases 1 and 2, and empty value for case 3. But I didn't see option "-d" in three results. Could you please someone explain me why CommandLine returns unexpected value in ServiceMode?

Antworten:

local service account doesn't have access to write to the file location specified.

von CCC2 - am 09.03.2016 11:29
Hi,

you are not showing us the most important part : the FULL commandline you are setting for the service.

So your syntax should get the SECOND parameter of the line, but as we don't know what they are...

Best regards

von Fabrice Harari - am 09.03.2016 11:35
My experience with services is that CommandLine() works differently than with a regular windows program.

With a regular windows program CommandLine(1) is the first parameter. With a service, CommandLine(1) is the entire command line and CommandLine(2) is the first parameter.

I normally have to do some registry edits to get command line parameters working correctly. I have never been able to get the parameters option working from the windows service screen. Parameters do work and I suspect your problem is that you don't have things setup correctly in the registry.

Stewart Crisler

von Stewart Crisler - am 09.03.2016 18:54
Quote
Fabrice Harari
you are not showing us the most important part : the FULL commandline you are setting for the service.

Actually I don't use Service.* structure at all. (Should I?) Usually I create an installation package for service and it is installed in system by WinDev installer. And as I already wrote I use Services Management Console to stop service and run it with parameter. I mean this

von Arekusei Timakobu - am 09.03.2016 21:03
Quote
Stewart Crisler
With a regular windows program CommandLine(1) is the first parameter. With a service, CommandLine(1) is the entire command line and CommandLine(2) is the first parameter.

Yes, you are absolutely right and I also know this.

Quote
Stewart Crisler
I normally have to do some registry edits to get command line parameters working correctly.

What edits?

Quote
Stewart Crisler
Parameters do work and I suspect your problem is that you don't have things setup correctly in the registry.

As I've mentioned above I don't do any special things. I just create install with "Setup" button in WinDev and service is installed automatically.

von Arekusei Timakobu - am 09.03.2016 21:11
In terms of registry edits, I don't have access to a machine that has a working example so I am unable to be very specific. As I recall, I found the registry key that launches the program and then edited that line to incorporate the parameter(s) that I want just like you would type it on a command line if you were launching the program that way. You should be able to find the key by searching for the service name shown in Manage Services. From there a little sleuthing should get you to the correct key.

Your other debugging alternative is to install the remote debugging tool supplied by WinDev that will let you debug running code even on another machine. I have played with this a little bit with a multithreaded application but never conquered the threading part of debugging. Depending on what you are trying to take a look at, this might be your best bet. No changes are needed to your program.

Stewart Crisler

von Stewart Crisler - am 10.03.2016 04:55
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.