PC Review


Reply
Thread Tools Rate Thread

Creating a Process from a windows service

 
 
=?Utf-8?B?Tm9hbQ==?=
Guest
Posts: n/a
 
      20th Jun 2006
I had originally written a program as a c# console application. The program
used a reference that I wrote in c++. Later I was told to re-write the
application as a windows service. When the service would start up, as soon as
it accessed the reference (by instantiating a class within the reference),
the service would crash. In the event viewer I saw that it throw a
System.IO.FileNotFoundException saying that the c++ reference was missing
(even though it was in the same directory as the .exe). I decided to write a
windows service that would simply launch the console application. In the
“OnStart” method I called the win32 API CreateProcess (which I P/Invoked).
When the service started it launched the console application successfully,
the console application then as soon as the reference was "used" by the
console application the console application crashes saying
File.IO.FileNotFoundException. As sanity check first I ran the console app by
itself and it ran just fine. Then I created a second c# console application
and in the main I used the exact same code from the “OnStart” of the afore
mentioned service (CreateProcess api) and it launched my original program
just fine.

Why is there a difference if I use CreateProcess from a c# service vs. c#
console application? Also isn't a service simply a console application that
interacts with service control manager?

 
Reply With Quote
 
 
 
 
Chris Dunaway
Guest
Posts: n/a
 
      20th Jun 2006
Noam wrote:

> Why is there a difference if I use CreateProcess from a c# service vs. c#
> console application? Also isn't a service simply a console application that
> interacts with service control manager?


When you ran the console application manually, you were logged in to
Windows. When your service executed, it logged in differently, using
the LocalSystem account which is restricted.

Without knowing what the process you are trying to start does, I can't
say exactly why you got the FileNotFound exception, but it may be that
the LocalSystem account does not have the necessary permissions to
access some resource needed by the process.

What happens when you set the service to log in as yourself, can it
then run correctly?

 
Reply With Quote
 
=?Utf-8?B?Tm9hbQ==?=
Guest
Posts: n/a
 
      20th Jun 2006
Thank you so much for getting back to me so quickly I really appreciate it.
In the Log On tab under the service I had it set to my domain\username and
password (so the service is not set under Local System account). Also my
company uses active directory and I am an administrator on my computer. Still
no dice

"Chris Dunaway" wrote:

> Noam wrote:
>
> > Why is there a difference if I use CreateProcess from a c# service vs. c#
> > console application? Also isn't a service simply a console application that
> > interacts with service control manager?

>
> When you ran the console application manually, you were logged in to
> Windows. When your service executed, it logged in differently, using
> the LocalSystem account which is restricted.
>
> Without knowing what the process you are trying to start does, I can't
> say exactly why you got the FileNotFound exception, but it may be that
> the LocalSystem account does not have the necessary permissions to
> access some resource needed by the process.
>
> What happens when you set the service to log in as yourself, can it
> then run correctly?
>
>

 
Reply With Quote
 
chanmm
Guest
Posts: n/a
 
      20th Jun 2006
Can you specifiy the full path rather than depend on the default exe folder?

chanmm

"Noam" <(E-Mail Removed)> wrote in message
news:0C8A48C2-B488-472D-B509-(E-Mail Removed)...
>I had originally written a program as a c# console application. The program
> used a reference that I wrote in c++. Later I was told to re-write the
> application as a windows service. When the service would start up, as soon
> as
> it accessed the reference (by instantiating a class within the reference),
> the service would crash. In the event viewer I saw that it throw a
> System.IO.FileNotFoundException saying that the c++ reference was missing
> (even though it was in the same directory as the .exe). I decided to write
> a
> windows service that would simply launch the console application. In the
> "OnStart" method I called the win32 API CreateProcess (which I
> P/Invoked).
> When the service started it launched the console application successfully,
> the console application then as soon as the reference was "used" by the
> console application the console application crashes saying
> File.IO.FileNotFoundException. As sanity check first I ran the console app
> by
> itself and it ran just fine. Then I created a second c# console
> application
> and in the main I used the exact same code from the "OnStart" of the afore
> mentioned service (CreateProcess api) and it launched my original program
> just fine.
>
> Why is there a difference if I use CreateProcess from a c# service vs. c#
> console application? Also isn't a service simply a console application
> that
> interacts with service control manager?
>



 
Reply With Quote
 
=?Utf-8?B?Tm9hbQ==?=
Guest
Posts: n/a
 
      20th Jun 2006
I'm not sure i understand your answer, when you say specify the full path are
you referring to the path to the CreateProcess api (that i am passing) or for
the reference that i am recieving the System.IO.FileNotFoungException? If it
is for the reference my understanding is that all references (if not in the
GAC) must be in the same directory as the .exe... Also I have other refernces
in that directory that the program is picking up just fine.

Here is some informtaion on the c++ referance that is throwing the error.
Configuration type: Dynamic Libray
MFC: Use MFC in a Shared DLL
Runtime Library: /MDd

every other value is the default


"chanmm" wrote:

> Can you specifiy the full path rather than depend on the default exe folder?
>
> chanmm
>
> "Noam" <(E-Mail Removed)> wrote in message
> news:0C8A48C2-B488-472D-B509-(E-Mail Removed)...
> >I had originally written a program as a c# console application. The program
> > used a reference that I wrote in c++. Later I was told to re-write the
> > application as a windows service. When the service would start up, as soon
> > as
> > it accessed the reference (by instantiating a class within the reference),
> > the service would crash. In the event viewer I saw that it throw a
> > System.IO.FileNotFoundException saying that the c++ reference was missing
> > (even though it was in the same directory as the .exe). I decided to write
> > a
> > windows service that would simply launch the console application. In the
> > "OnStart" method I called the win32 API CreateProcess (which I
> > P/Invoked).
> > When the service started it launched the console application successfully,
> > the console application then as soon as the reference was "used" by the
> > console application the console application crashes saying
> > File.IO.FileNotFoundException. As sanity check first I ran the console app
> > by
> > itself and it ran just fine. Then I created a second c# console
> > application
> > and in the main I used the exact same code from the "OnStart" of the afore
> > mentioned service (CreateProcess api) and it launched my original program
> > just fine.
> >
> > Why is there a difference if I use CreateProcess from a c# service vs. c#
> > console application? Also isn't a service simply a console application
> > that
> > interacts with service control manager?
> >

>
>
>

 
Reply With Quote
 
Ben Voigt
Guest
Posts: n/a
 
      20th Jun 2006
"Noam" <(E-Mail Removed)> wrote in message
news:ECAC76A8-3C72-4320-8192-(E-Mail Removed)...
> I'm not sure i understand your answer, when you say specify the full path
> are
> you referring to the path to the CreateProcess api (that i am passing) or
> for
> the reference that i am recieving the System.IO.FileNotFoungException? If
> it
> is for the reference my understanding is that all references (if not in
> the
> GAC) must be in the same directory as the .exe... Also I have other
> refernces
> in that directory that the program is picking up just fine.


Can you somehow run your process through depends.exe, possibly by changing
your CreateProcess call? Depends.exe will watch the process and tell you
more about why the DLL failed to load. Although you will have trouble
getting the window to be visible so you can interact and inspect it....
services running as user accounts run in a separate desktop by default.

>
> Here is some informtaion on the c++ referance that is throwing the error.
> Configuration type: Dynamic Libray
> MFC: Use MFC in a Shared DLL
> Runtime Library: /MDd


Does your DLL have a DllMain? Doing anything significant there?

>
> every other value is the default
>
>
> "chanmm" wrote:
>
>> Can you specifiy the full path rather than depend on the default exe
>> folder?
>>
>> chanmm
>>
>> "Noam" <(E-Mail Removed)> wrote in message
>> news:0C8A48C2-B488-472D-B509-(E-Mail Removed)...
>> >I had originally written a program as a c# console application. The
>> >program
>> > used a reference that I wrote in c++. Later I was told to re-write the
>> > application as a windows service. When the service would start up, as
>> > soon
>> > as
>> > it accessed the reference (by instantiating a class within the
>> > reference),
>> > the service would crash. In the event viewer I saw that it throw a
>> > System.IO.FileNotFoundException saying that the c++ reference was
>> > missing
>> > (even though it was in the same directory as the .exe). I decided to
>> > write
>> > a
>> > windows service that would simply launch the console application. In
>> > the
>> > "OnStart" method I called the win32 API CreateProcess (which I
>> > P/Invoked).
>> > When the service started it launched the console application
>> > successfully,
>> > the console application then as soon as the reference was "used" by the
>> > console application the console application crashes saying
>> > File.IO.FileNotFoundException. As sanity check first I ran the console
>> > app
>> > by
>> > itself and it ran just fine. Then I created a second c# console
>> > application
>> > and in the main I used the exact same code from the "OnStart" of the
>> > afore
>> > mentioned service (CreateProcess api) and it launched my original
>> > program
>> > just fine.
>> >
>> > Why is there a difference if I use CreateProcess from a c# service vs.
>> > c#
>> > console application? Also isn't a service simply a console application
>> > that
>> > interacts with service control manager?
>> >

>>
>>
>>



 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      20th Jun 2006


"Noam" <(E-Mail Removed)> wrote in message
news:ECAC76A8-3C72-4320-8192-(E-Mail Removed)...
| I'm not sure i understand your answer, when you say specify the full path
are
| you referring to the path to the CreateProcess api (that i am passing) or
for
| the reference that i am recieving the System.IO.FileNotFoungException? If
it
| is for the reference my understanding is that all references (if not in
the
| GAC) must be in the same directory as the .exe... Also I have other
refernces
| in that directory that the program is picking up just fine.
|
| Here is some informtaion on the c++ referance that is throwing the error.
| Configuration type: Dynamic Libray
| MFC: Use MFC in a Shared DLL
| Runtime Library: /MDd
|

As far as I see you have a MFC DLL as "reference", right.
Questions are:
- what version of the C compiler was used to build this DLL? If it's VC 8
(vs2005), the DLL must contain an embedded manifest if the CRT library is
not statically linked.
- this DLL is in the same path as the exe?
- this DLL is built using the /clr option, right?

Willy.






 
Reply With Quote
 
=?Utf-8?B?Tm9hbQ==?=
Guest
Posts: n/a
 
      20th Jun 2006
Again thank you so much for the reply I really apreciate everyones help. I am
using Visual Studios 2003 Verssion 7.1.3088. The dll is in the same path as
the exe and the /clr option was used.

"Willy Denoyette [MVP]" wrote:

>
>
> "Noam" <(E-Mail Removed)> wrote in message
> news:ECAC76A8-3C72-4320-8192-(E-Mail Removed)...
> | I'm not sure i understand your answer, when you say specify the full path
> are
> | you referring to the path to the CreateProcess api (that i am passing) or
> for
> | the reference that i am recieving the System.IO.FileNotFoungException? If
> it
> | is for the reference my understanding is that all references (if not in
> the
> | GAC) must be in the same directory as the .exe... Also I have other
> refernces
> | in that directory that the program is picking up just fine.
> |
> | Here is some informtaion on the c++ referance that is throwing the error.
> | Configuration type: Dynamic Libray
> | MFC: Use MFC in a Shared DLL
> | Runtime Library: /MDd
> |
>
> As far as I see you have a MFC DLL as "reference", right.
> Questions are:
> - what version of the C compiler was used to build this DLL? If it's VC 8
> (vs2005), the DLL must contain an embedded manifest if the CRT library is
> not statically linked.
> - this DLL is in the same path as the exe?
> - this DLL is built using the /clr option, right?
>
> Willy.
>
>
>
>
>
>
>

 
Reply With Quote
 
=?Utf-8?B?Tm9hbQ==?=
Guest
Posts: n/a
 
      20th Jun 2006
Thank you so much for your reply. My dll is not a regular dll it is a visual
studios assembly. As such there is no dll main. I am trying depends.exe now
but I haven’t seen anything useful.

"Ben Voigt" wrote:

> "Noam" <(E-Mail Removed)> wrote in message
> news:ECAC76A8-3C72-4320-8192-(E-Mail Removed)...
> > I'm not sure i understand your answer, when you say specify the full path
> > are
> > you referring to the path to the CreateProcess api (that i am passing) or
> > for
> > the reference that i am recieving the System.IO.FileNotFoungException? If
> > it
> > is for the reference my understanding is that all references (if not in
> > the
> > GAC) must be in the same directory as the .exe... Also I have other
> > refernces
> > in that directory that the program is picking up just fine.

>
> Can you somehow run your process through depends.exe, possibly by changing
> your CreateProcess call? Depends.exe will watch the process and tell you
> more about why the DLL failed to load. Although you will have trouble
> getting the window to be visible so you can interact and inspect it....
> services running as user accounts run in a separate desktop by default.
>
> >
> > Here is some informtaion on the c++ referance that is throwing the error.
> > Configuration type: Dynamic Libray
> > MFC: Use MFC in a Shared DLL
> > Runtime Library: /MDd

>
> Does your DLL have a DllMain? Doing anything significant there?
>
> >
> > every other value is the default
> >
> >
> > "chanmm" wrote:
> >
> >> Can you specifiy the full path rather than depend on the default exe
> >> folder?
> >>
> >> chanmm
> >>
> >> "Noam" <(E-Mail Removed)> wrote in message
> >> news:0C8A48C2-B488-472D-B509-(E-Mail Removed)...
> >> >I had originally written a program as a c# console application. The
> >> >program
> >> > used a reference that I wrote in c++. Later I was told to re-write the
> >> > application as a windows service. When the service would start up, as
> >> > soon
> >> > as
> >> > it accessed the reference (by instantiating a class within the
> >> > reference),
> >> > the service would crash. In the event viewer I saw that it throw a
> >> > System.IO.FileNotFoundException saying that the c++ reference was
> >> > missing
> >> > (even though it was in the same directory as the .exe). I decided to
> >> > write
> >> > a
> >> > windows service that would simply launch the console application. In
> >> > the
> >> > "OnStart" method I called the win32 API CreateProcess (which I
> >> > P/Invoked).
> >> > When the service started it launched the console application
> >> > successfully,
> >> > the console application then as soon as the reference was "used" by the
> >> > console application the console application crashes saying
> >> > File.IO.FileNotFoundException. As sanity check first I ran the console
> >> > app
> >> > by
> >> > itself and it ran just fine. Then I created a second c# console
> >> > application
> >> > and in the main I used the exact same code from the "OnStart" of the
> >> > afore
> >> > mentioned service (CreateProcess api) and it launched my original
> >> > program
> >> > just fine.
> >> >
> >> > Why is there a difference if I use CreateProcess from a c# service vs.
> >> > c#
> >> > console application? Also isn't a service simply a console application
> >> > that
> >> > interacts with service control manager?
> >> >
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
John Vottero
Guest
Posts: n/a
 
      20th Jun 2006

"Noam" <(E-Mail Removed)> wrote in message
news:0C8A48C2-B488-472D-B509-(E-Mail Removed)...

[snip]

> Why is there a difference if I use CreateProcess from a c# service vs. c#
> console application? Also isn't a service simply a console application
> that
> interacts with service control manager?


One key difference between running a console app and a windows service is
the default directory. Try changing your directory to C:\Windows\System32
then run your console app from there (by entering the full path to the
console exe). Does that work? I think it will fail the same way that the
service is failing. If it does, make your service change it's directory via
System.Environment.CurrentDirectory.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.net creating windows service to kill specified process ZD Microsoft Dot NET Framework 0 11th Sep 2006 09:15 AM
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific permitions? Daniel Microsoft Dot NET Framework 1 13th Apr 2006 04:56 AM
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific permitions? Daniel Microsoft Windows 2000 Security 0 12th Apr 2006 11:47 PM
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific permitions? Daniel Microsoft C# .NET 0 12th Apr 2006 11:47 PM
what permissions does a windows service need to execute another process? System.Diagnostics.Process process = System.Diagnostics.Process.Start(info); just local administrator? any specific permitions? Daniel Microsoft Dot NET 0 12th Apr 2006 11:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:28 AM.