Hi,

I have created a executable that gets deployed as a windows service
via Installshield..
This exe calls a bat file internally to launch a java application..
The problem i'm facing is it does not start the bat file when the
service gets started from services menu..it calls the bat file when
executed outside the purview of the service..
The bat file and the exe are on the same folder..
The path to this folder is added to path env var..

Please tell me what could be wrong..

Thanks,
NKH

Re: NT service exe notcalling bat files via shellexecute by Mark

Mark
Wed Jul 23 12:34:03 CDT 2008


"NKH" <nishantnow@gmail.com> wrote in message
news:c164f84e-a02f-447d-9227-17ecb3376534@a2g2000prm.googlegroups.com...
> Hi,
>
> I have created a executable that gets deployed as a windows service
> via Installshield..
> This exe calls a bat file internally to launch a java application..
> The problem i'm facing is it does not start the bat file when the
> service gets started from services menu..it calls the bat file when
> executed outside the purview of the service..
> The bat file and the exe are on the same folder..
> The path to this folder is added to path env var..
>
> Please tell me what could be wrong..



Debugging the app and checking for a returned ShellExecute error code may be
a helpful start :)

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++


>
> Thanks,
> NKH


Re: NT service exe notcalling bat files via shellexecute by Igor

Igor
Wed Jul 23 12:40:24 CDT 2008

NKH <nishantnow@gmail.com> wrote:
> I have created a executable that gets deployed as a windows service
> via Installshield..
> This exe calls a bat file internally to launch a java application..
> The problem i'm facing is it does not start the bat file when the
> service gets started from services menu..it calls the bat file when
> executed outside the purview of the service..

How do you know it doesn't start the BAT file?

Be aware that services run in their own dedicated window station,
separate from your interactive desktop. So do processes spawned by
services. In other words, if a service runs a windowed application, the
user (you) won't see it.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925



Re: NT service exe notcalling bat files via shellexecute by Tamas

Tamas
Wed Jul 23 15:55:45 CDT 2008

NKH wrote:

> The problem i'm facing is it does not start the bat file when the
> service gets started from services menu..it calls the bat file when
> executed outside the purview of the service..

Services by default run under a special user, with very restricted
privileges. The service may not have permission to read, write, execute
in most of the folders. Usually C:\Documents and Settings\LocalService\
is accessible from services.

> The bat file and the exe are on the same folder..
> The path to this folder is added to path env var..

Some of the environment variables are user-specific, so services may see
a different PATH variable than you as a user. I would use full paths,
even if the files are located in the same directory as the service.

My recommendation is to try to trace variables (such as function return
values) to a log file, and analyze that file for hints of errors. Or use
OutputDebugString with DebugView:
http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx

Tom

Re: NT service exe notcalling bat files via shellexecute by Alexander

Alexander
Wed Jul 23 21:20:31 CDT 2008

It may not be a good idea to use ShellExecute in a service at all. Use plain
CreateProcess. Use full paths for bat file.

"NKH" <nishantnow@gmail.com> wrote in message
news:c164f84e-a02f-447d-9227-17ecb3376534@a2g2000prm.googlegroups.com...
> Hi,
>
> I have created a executable that gets deployed as a windows service
> via Installshield..
> This exe calls a bat file internally to launch a java application..
> The problem i'm facing is it does not start the bat file when the
> service gets started from services menu..it calls the bat file when
> executed outside the purview of the service..
> The bat file and the exe are on the same folder..
> The path to this folder is added to path env var..
>
> Please tell me what could be wrong..
>
> Thanks,
> NKH



Re: NT service exe notcalling bat files via shellexecute by NKH

NKH
Fri Jul 25 10:08:59 CDT 2008

On Jul 24, 7:20=A0am, "Alexander Grigoriev" <al...@earthlink.net> wrote:
> It may not be a good idea to use ShellExecute in a service at all. Use pl=
ain
> CreateProcess. Use full paths for bat file.
>
> "NKH" <nishant...@gmail.com> wrote in message
>
> news:c164f84e-a02f-447d-9227-17ecb3376534@a2g2000prm.googlegroups.com...
>
>
>
> > Hi,
>
> > I have created a executable that gets deployed as a windows service
> > via Installshield..
> > This exe calls a bat file internally to launch a java application..
> > The problem i'm facing is it does not start the bat file when the
> > service gets started from services menu..it calls the bat file when
> > executed outside the purview of the service..
> > The bat file and the exe are on the same folder..
> > The path to this folder is added to path env var..
>
> > Please tell me what could be wrong..
>
> > Thanks,
> >NKH- Hide quoted text -
>
> - Show quoted text -

I had used CreateProcess but it gave me error file not found..I tried
debugging with ShellExecute, it gv a return value 002..not sure what
that meant..

Thanks,
NKH

Re: NT service exe notcalling bat files via shellexecute by Tamas

Tamas
Mon Jul 28 15:22:32 CDT 2008

NKH wrote:

> I had used CreateProcess but it gave me error file not found..I tried
> debugging with ShellExecute, it gv a return value 002..not sure what
> that meant..

From WinError.h:
#define ERROR_FILE_NOT_FOUND 2L

So that means the filename points to a non-existing file, or the service
can't see the file (perhaps because it's running under a different
account, which doesn't have access to it).

You need to move that file into a directory where the service account
can see. Or you can make the service account log on as a user. Or you
could use LogonUser + ImpersonateLoggedOnUser to programmatically switch
to the context of another user before CreateProcess.

In the long run it is not a good idea to run a service as an
Administrator, though. Also note that not every user account can be used
to run as a service. See these links to see how to allow a user to be
run as a service:

If you're on a domain:
http://www.greyware.com/software/rum/rights.asp

Otherwise (local users):
http://kinnie.blogspot.com/2005/12/log-on-as-service.html

Tom