473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem using the shell function in a service.

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
9 1502
"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
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
"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
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
"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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Will Seay | last post by:
At the end of this message I've pasted a script we're trying to modify slightly. I don't believe it is VBscript or javascript but these are the closest groups I could find with my limited...
9
by: none | last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs to be modified. The problem I have is this: The SysAdmin uses this shell in place of Explorer, so there is no taskbar. When...
2
by: Xah Lee | last post by:
Python Doc Problem Example: os.system Xah Lee, 2005-09 today i'm trying to use Python to call shell commands. e.g. in Perl something like output=qx(ls) in Python i quickly located the...
1
by: JerryKreps | last post by:
Hi, folks -- I'm a Python pup. As you can see from the session copied at the end of this post, I have the latest version of Python, and I've been using the Editor-Shell of the latest version of...
8
by: skinnybloke | last post by:
Hi - I am a newbie to Access & SQL and I would appreciate some help on this if at all possible. I have a query that contains the following code. SELECT DISTINCT Product. AS , Product. AS ; ...
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
5
by: Rob R. Ainscough | last post by:
I'm using the Diagnostics.Process approach to shelling out run the following: C:\Windows\System32\MSIEXEC.EXE /x {73F1BDB7-11E1-11D5-9DC6-00C04F2FC33B} /q ..FileName =...
1
by: Sh0t2bts | last post by:
Hi, I am using the below command to restart a service on one of my web boxes, this runs fine from the command prompt and also through a *.bat file. ...
1
by: Mark Shewfelt | last post by:
Hello, I am attempting to use Popen() in a Windows service. I have a small Win32 .exe that I normally run through the os.popen2() function. I've written a class to work with the input and output...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.