Determine command line parameters from invoked Desktop session

I am attempting to launch a Delphi Winform executable (with a command line argument) from a WinService, in an environment which does not support Interactive Services (i.e. Win7/XP SP3).  Please see my original post (Q_26873780) for reference.

I am using a C# variation of an excellent (ServiceShell) code snippet found in
Q_26726314 to launch executables with command line arguments.

Unfortuntely the Delphi 'ParamCount' method always returns 0 when I use the aforementioned C# version of the ServiceShell call, whereas when calling other programs (such as notepad.exe) with a command line argument everything works perfectly.

Can anyone suggest an alternative to using ParamCount to determine my arguments? Or indeed any other method which might be at my disposal?
brenlexAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aikimarkCommented:
what is in the CmdLine and the Paramstr(0) variables?
0
systanCommented:
how about;
GetCommandLine
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BdLmCommented:
How did you start your program ?  
Paramstr(i)  and Paramcount should do it for you
0
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

BdLmCommented:
sample code goed like that

 for i:= 0 to paramcount do
      begin
      /// eg. KEYWORD : debug
       if LowerCase(ParamStr(i)) = 'debug' then



     end;
0
brenlexAuthor Commented:
My Delphi program is a long standing tried and tested applicaton -- when started from the windows command line with arguments it starts OK (i.e. paramcount is > 0), however when I use the code snippet from Q_26726314 my paramcount is 0.  As mentioned, I am using the aforementioned code snippet to launch my application because it is being launched from a service which needs to interact with the desktop (for background see original question (Q_26873780).

The strange thing is that it is only a Delphi program which has the problem.  
i.e.
ServiceShell.Start("C:\\temp\\notepad.exe", "C:\\temp\\mycfgfile.txt", "C:\\temp")
... works OK.  Notepad opens up showing the contents of mycfgfile.txt.
However,
ServiceShell.Start("C:\\temp\\mydelphiapp.exe", "C:\\temp\\mycfgfile.txt", "C:\\temp")
... launches mydelphiapp.exe but paramcount returns 0.  As mentioned, if I just use "C:\temp\mydelphiapp.exe C:\temp\mycfgfile.txt" from command line manually, paramcount is > 0.

0
BdLmCommented:


I think you need to call PChar(MyPath) .... can you trie it ?
0
brenlexAuthor Commented:
Strange one -- I thought ParamCount implicitly called GetCommandLine, though it appeared not to work.  When I myself call GetCommandLineW explicitly, I see my argument OK.

I'll give the points here to systan for the original recommendation to use GetCommandLine directly.
BdLm - thanks for making me think along the lines of PChar -- I shall give you the points in the parallel question in the VB.net zone you also commented on.
0
systanCommented:
thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.