🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
10 messages
10 total messages Started by Mike Collins Sun, 15 Jun 2008 17:57
CreateProcessAsUserW and quoted path names...
#142
Author: Mike Collins
Date: Sun, 15 Jun 2008 17:57
47 lines
3102 bytes
Hi all, I've got a problem that's just appeared today.  Software system has 
been working fine for the last month so I assume MS have updated something.

I have a service that runs and monitors certain aspect of the users 
computer.  We have a system tray application that is used to relay 
information to and from the users desktop via an IPC conduit (since the 
system needs to work in vista and XP, and vista isolates services into 
session 0).

When the user double-clicks on the system tray app, an IPC message is sent 
to the service, which in turn launches a configuration application on the 
users desktop.  The code does this in the following stages:

1) WTSGetActiveConsoleSessionId();
2) WTSQueryUserToken();
3) DuplicateTokenEx();
4) CreateEnvironBlock();
5) CreateProcessAsUserW();

- until today, this code was working fine.  However, CreateProcessAsUser has 
started to return an error code, 123, The filename, directory name, or 
volume label syntax is incorrect.  The second parameter (lpApplicationName) 
to this call is created thus:

WideString wzAppName = (WideString)("\"" + Utils->getControlCentreExePath() 
+ "\"");

In the MSDN documentation, it states:

"If you are using a long file name that contains a space, use quoted strings 
to indicate where the file name ends and the arguments begin; otherwise, the 
file name is ambiguous. For example, consider the string "c:\program 
files\sub dir\program name". This string can be interpreted in a number of 
ways."

So to avoid the possibility of rouge program trying to imitate our config 
application, I use quotes around the path.  This seems to be causing the 
problem.  If I remove the double-quotes, the code works, but there is the 
potential of another application being placed in the root directory (with 
the same name) and being launched instead of ours.

Can anyone help me out there.  Does anyone know a work around or have any 
suggestions?

Many thanks in advance,

Mike
Re: CreateProcessAsUserW and quoted path names...
#144
Author: Ed Mulroy [TeamB]
Date: Sun, 15 Jun 2008 20:12
62 lines
3397 bytes
> ...
> WideString wzAppName = (WideString)("\"" + 
> Utils->getControlCentreExePath() + "\"");
> ...
> If I remove the double-quotes, the code works, but ...

Just a SWAG but might you have quoted twice?

    ""PathAndFileName""
              instead of

    "PathAndFileName"

.  Ed

> Mike Collins wrote in message
> news:4855474a@newsgroups.borland.com...
>
> Hi all, I've got a problem that's just appeared today.  Software system 
> has been working fine for the last month so I assume MS have updated 
> something.
>
> I have a service that runs and monitors certain aspect of the users 
> computer.  We have a system tray application that is used to relay 
> information to and from the users desktop via an IPC conduit (since the 
> system needs to work in vista and XP, and vista isolates services into 
> session 0).
>
> When the user double-clicks on the system tray app, an IPC message is sent 
> to the service, which in turn launches a configuration application on the 
> users desktop.  The code does this in the following stages:
>
> 1) WTSGetActiveConsoleSessionId();
> 2) WTSQueryUserToken();
> 3) DuplicateTokenEx();
> 4) CreateEnvironBlock();
> 5) CreateProcessAsUserW();
>
> - until today, this code was working fine.  However, CreateProcessAsUser 
> has started to return an error code, 123, The filename, directory name, or 
> volume label syntax is incorrect.  The second parameter 
> (lpApplicationName) to this call is created thus:
>
> WideString wzAppName = (WideString)("\"" + 
> Utils->getControlCentreExePath() + "\"");
>
> In the MSDN documentation, it states:
>
> "If you are using a long file name that contains a space, use quoted 
> strings to indicate where the file name ends and the arguments begin; 
> otherwise, the file name is ambiguous. For example, consider the string 
> "c:\program files\sub dir\program name". This string can be interpreted in 
> a number of ways."
>
> So to avoid the possibility of rouge program trying to imitate our config 
> application, I use quotes around the path.  This seems to be causing the 
> problem.  If I remove the double-quotes, the code works, but there is the 
> potential of another application being placed in the root directory (with 
> the same name) and being launched instead of ours.
>
> Can anyone help me out there.  Does anyone know a work around or have any 
> suggestions?
Re: CreateProcessAsUserW and quoted path names...
#143
Author: Bob Gonder
Date: Sun, 15 Jun 2008 20:26
22 lines
1735 bytes
Mike Collins wrote:

>5) CreateProcessAsUserW();
>
>- until today, this code was working fine.  However, CreateProcessAsUser has 
>started to return an error code, 123, The filename, directory name, or 
>volume label syntax is incorrect.  The second parameter (lpApplicationName) 
>to this call is created thus:
>
>WideString wzAppName = (WideString)("\""+Utils->getControlCentreExePath()+"\"");

What type does getControlCentreExePath() return?
You are adding two narrow strings to it, and
lying about the result being a wide string.

Might work better if you use all wide string, or all normal string.

WideString wzApp = "\""L + Utils->getControlCentreExePathW() + "\""L;
CreateProcessAsUserW( ,wzApp.c_bstr(),);

String szApp = "\"" + Utils->getControlCentreExePathA() + "\"";
CreateProcessAsUserA( ,szApp.c_str(),);
Re: CreateProcessAsUserW and quoted path names...
#146
Author: Bob Gonder
Date: Sun, 15 Jun 2008 22:22
20 lines
1690 bytes
Mike Collins wrote:

>getControlCentreExePath() returns an ansi string, it's just a getter...

Then you are using the wrong function.
you are passing an ansi string to a function expecting a widestring.

(WideString)("\""... doesn't magically convert ansi to wide. It just
lies to the compiler to keep it from properly telling you things.

WideString wzAppName = (WideString)("\""....

operator WideString= requires a WideString, AnsiString or char* on the right.
You are supplying none of those.

I think this should do it...
AnsiString asTemp = "\"" + Utils->getControlCentreExePath() + AnsiString("\"");
WideString wzAppName( asTemp );

See the paramter list for friend operator +
Re: CreateProcessAsUserW and quoted path names...
#145
Author: Mike Collins
Date: Sun, 15 Jun 2008 22:36
10 lines
1314 bytes
Cheers bob,

getControlCentreExePath() returns an ansi string, it's just a getter...

Does it matter where you use the L macro?  Does it matter if it is before 
the text that you want to be considered as a unicode string?

I'll have a play and report back

Mike 
Re: CreateProcessAsUserW and quoted path names...
#150
Author: Remy Lebeau (TeamB)
Date: Mon, 16 Jun 2008 16:52
19 lines
1521 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote in message 
news:4855474a@newsgroups.borland.com...

> The second parameter (lpApplicationName) to this call is created thus:

I suggest ignoring the lpApplicationName parameter altogether and pass 
everything in the lpCommandLine parameter instead, ie:

    ... = CreateProcessAsUser(hToken, NULL, "filename and paraeters here 
only", ...);

> In the MSDN documentation, it states:

That only applies if you are passing additional parameters in addition to 
the .exe filename.  Are you actually doing that?


Gambit 
Re: CreateProcessAsUserW and quoted path names...
#157
Author: Mike Collins
Date: Wed, 18 Jun 2008 10:29
19 lines
1613 bytes
Hay Bob, sorry for the lateness, have been away from my desk for a few days.

Thanks for the suggestions, I'm going to have a look at it now.

Just out of interest, the docs say that you can use the = operator with a 
WideString and assign an AnsiString this way, based on this, would the 
following be a better solution (this is purly out of interest):

 WideString wzAppName = AnsiString("\"" + Utils->getControlCentreExePath() + 
"\"");

Thanks again,

Mike

"Bob Gonder" <none@nowhere.invalid> wrote in message 
news:933b54p734ss9a639pu6qs5t34ripfgl77@4ax.com...
> Mike Collins wrote:
>
Re: CreateProcessAsUserW and quoted path names...
#158
Author: Mike Collins
Date: Wed, 18 Jun 2008 10:30
13 lines
1344 bytes
Err, I'm passing the path and exe name in the lpApplicationName parameter 
and some addition switches in the lpCommandLine parameter.  I take it that 
you are suggesting passing eveything in the lpCommandLine parameter?

I'll give it a shot now and see what i get.

Thanks again,

Mike

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:48569aa9$1@newsgroups.borland.com...
>
Re: CreateProcessAsUserW and quoted path names...
#160
Author: Bob Gonder
Date: Wed, 18 Jun 2008 16:33
11 lines
1380 bytes
Mike Collins wrote:

>Err, I'm passing the path and exe name in the lpApplicationName parameter 
>and some addition switches in the lpCommandLine parameter.  I take it that 
>you are suggesting passing eveything in the lpCommandLine parameter?

You can use both:
lpApplicationName = App.exe
lpCommandLine = App.exe Arg1 Arg2

So the application is argv[0], which is expected by the application.
Re: CreateProcessAsUserW and quoted path names...
#161
Author: Bob Gonder
Date: Wed, 18 Jun 2008 16:45
18 lines
1830 bytes
Mike Collins wrote:

>Just out of interest, the docs say that you can use the = operator with a 
>WideString and assign an AnsiString this way, based on this, would the 
>following be a better solution (this is purly out of interest):
>
> WideString wzAppName = AnsiString("\"" + Utils->getControlCentreExePath() + 
>"\"");

Take a moment to reflect on your "addition"...
What does "ABC" + "DEF" + "GHI" mean?
Is there some magic somewhere that adds char* to char* ?

See my previous conversion, and collaps it if you wish.

Now, if instead of returning an ansi string,
getControlCentreExePath()returned AnsiString, then you could do
WideString wzAppName = "\"" + Utils->getControlCentreExePath() + "\"";
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads