By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,168 Members | 2,511 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,168 IT Pros & Developers. It's quick & easy.

Problem using the shell function in a service.

P: n/a
I have a small application that launches an application via the shell
function when a listening socket receives data from another PC. This works
fine using a WinForms environment.

However, I want this listing app to run in the background as a service.
When debugging the service, the line -

ID = Shell("C:\TestApp.exe", AppWinStyle.NormalFocus)

returns a PID value, executes without errors, but the program "TestApp.exe"
doesn't start. Task manager show TestApp as a running process, but it
really didn't because it would have incremented a value in a database.

Once again the code runs fine in WinForms but not as a service.

Any suggestions would be greatly appreciated.

Dave M
Mar 29 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"dave m" <da***@nexcortech.com> schrieb:
I have a small application that launches an application via the shell
function when a listening socket receives data from another PC. This
works fine using a WinForms environment.

However, I want this listing app to run in the background as a service.
When debugging the service, the line -

ID = Shell("C:\TestApp.exe", AppWinStyle.NormalFocus)

returns a PID value, executes without errors, but the program
"TestApp.exe" doesn't start. Task manager show TestApp as a running
process, but it really didn't because it would have incremented a value in
a database.


This doesn't work "by design". Services can even run if no user is logged
on and thus cannot have access to the desktop. I suggest to rethink whether
a service is the right choice. Maybe an application which gets started when
the user logs on is a viable alternative.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 29 '06 #2

P: n/a
CMM
Not sure this is correct, Herfried . 1) The user doesn't mention "the
desktop" does he? 2) In any case, Services can for sure interact with the
current desktop (if it's loaded) if they so wished. Why do you say they
cannot?

Anyway... Dave M,
1) you mention a "database." Services are typically set to run under the
Local System account and are limited in their network access. Have you tried
running your service under a different user account (you can configure this
in Windows' Computer Management console). But that brings up another
question....
2) I'm not sure if processes spawned using "Shell" inherit the environment
of the caller program if the caller is a service. They probably do. I'm
almost sure of it. But you may need to look into Process.Start (and possibly
ProcessStartInfo if you need fine-grained control) to spawn your process and
get it to work right with the right privileges.

--
-C. Moya
www.cmoya.com
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
"dave m" <da***@nexcortech.com> schrieb:
I have a small application that launches an application via the shell
function when a listening socket receives data from another PC. This
works fine using a WinForms environment.

However, I want this listing app to run in the background as a service.
When debugging the service, the line -

ID = Shell("C:\TestApp.exe", AppWinStyle.NormalFocus)

returns a PID value, executes without errors, but the program
"TestApp.exe" doesn't start. Task manager show TestApp as a running
process, but it really didn't because it would have incremented a value
in a database.


This doesn't work "by design". Services can even run if no user is logged
on and thus cannot have access to the desktop. I suggest to rethink
whether a service is the right choice. Maybe an application which gets
started when the user logs on is a viable alternative.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 30 '06 #3

P: n/a
"CMM" <cm*@nospam.com> schrieb:
Not sure this is correct, Herfried . 1) The user doesn't mention "the
desktop" does he? 2) In any case, Services can for sure interact with the
current desktop (if it's loaded) if they so wished. Why do you say they
cannot?


Services can interact with the desktop, but this is neither recommended nor
a suitable solution when starting other applications, IMO. Be aware that
the OP wanted to start the application in a way that its windows are visible
on the currently logged on user. Even starting the application under a
different user account using impersonation won't fix the problem.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 30 '06 #4

P: n/a
And I recall reading somewhere that in Windows Vista, services will *no
longer* be able to interact with the desktop so if the OP plans to
migrate to Vista when it comes out in January, it would be best to
avoid it.

Mar 30 '06 #5

P: n/a
"Chris Dunaway" <du******@gmail.com> schrieb:
And I recall reading somewhere that in Windows Vista, services will *no
longer* be able to interact with the desktop


That's IIRC true.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Mar 30 '06 #6

P: n/a
CMM
> the OP wanted to start the application in a way that its windows are
visible on the currently logged on user.


I misunderstood the OP in that case. You are right that if his intention is
to (eventually) launch an interactive app, it only makes sense to add his
"service" to "HKLM\...\Run" in the registry rather than have it run as a
service.

--
-C. Moya
www.cmoya.com
Mar 30 '06 #7

P: n/a
CMM
I highly doubt that. Service accounts may be "hardened" by default in Vista
but I can't see this functionality being completely taken away as it would
break stuff like the secondary logon services and RunAs... unless MS hides
the functionality for themselves which would violate almost every Anti-trust
ruling again it. I'm sure other 3rd party services might possibly break as
well (iPod watcher comes to mind as a possibility).

--
-C. Moya
www.cmoya.com
"Chris Dunaway" <du******@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
And I recall reading somewhere that in Windows Vista, services will *no
longer* be able to interact with the desktop so if the OP plans to
migrate to Vista when it comes out in January, it would be best to
avoid it.

Mar 30 '06 #8

P: n/a
"CMM" <cm*@nospam.com> schrieb:
I highly doubt that. Service accounts may be "hardened" by default in Vista
but I can't see this functionality being completely taken away as it would
break stuff like the secondary logon services and RunAs... unless MS hides
the functionality for themselves which would violate almost every
Anti-trust ruling again it. I'm sure other 3rd party services might
possibly break as well (iPod watcher comes to mind as a possibility).


I don't think this change would pose such a big problem. Impersonation will
still be possible in Vista, and services which require user interaction
can/should be split up into the service and a separate application which
runs on the user's desktop once the user logs on and then communicates with
the service. This approach has already been recommended by Microsoft for
some time now:

<URL:http://groups.google.de/group/microsoft.public.de.german.entwickler.dotnet.cshar p/msg/628a30f8d007de44>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 30 '06 #9

P: n/a
Thanks for taking the time to reply.! I see the errors of my ways and you
saved me alot of time and frustration!

Dave M
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eD**************@TK2MSFTNGP12.phx.gbl...
"dave m" <da***@nexcortech.com> schrieb:
I have a small application that launches an application via the shell
function when a listening socket receives data from another PC. This
works fine using a WinForms environment.

However, I want this listing app to run in the background as a service.
When debugging the service, the line -

ID = Shell("C:\TestApp.exe", AppWinStyle.NormalFocus)

returns a PID value, executes without errors, but the program
"TestApp.exe" doesn't start. Task manager show TestApp as a running
process, but it really didn't because it would have incremented a value
in a database.


This doesn't work "by design". Services can even run if no user is logged
on and thus cannot have access to the desktop. I suggest to rethink
whether a service is the right choice. Maybe an application which gets
started when the user logs on is a viable alternative.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 30 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.