473,395 Members | 1,791 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,395 software developers and data experts.

Creating a Process from a windows service

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?

Jun 20 '06 #1
12 6496
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?

Jun 20 '06 #2
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?

Jun 20 '06 #3
Can you specifiy the full path rather than depend on the default exe folder?

chanmm

"Noam" <No**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
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?

Jun 20 '06 #4
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" <No**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
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?


Jun 20 '06 #5
"Noam" <No**@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
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" <No**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
>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?
>


Jun 20 '06 #6


"Noam" <No**@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
| 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.


Jun 20 '06 #7
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" <No**@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
| 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.


Jun 20 '06 #8
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" <No**@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
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" <No**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
>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?
>


Jun 20 '06 #9

"Noam" <No**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...

[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.

Jun 20 '06 #10

How about running the service as the local system account and checking
"interact with desktop"?

"John Vottero" wrote:

"Noam" <No**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...

[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.

Jun 30 '06 #11

"Mike" <Mi**@discussions.microsoft.com> wrote in message
news:35**********************************@microsof t.com...
|
| How about running the service as the local system account and checking
| "interact with desktop"?
|

No, this doesn't have anything to do with the OP's issue, and, this is
something you should only consider when "debugging" a service, but not in
production.

Willy.

| "John Vottero" wrote:
|
| >
| > "Noam" <No**@discussions.microsoft.com> wrote in message
| > news:0C**********************************@microsof t.com...
| >
| > [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.
| >
| >
| >
| >
Jun 30 '06 #12
Thank you so much kind sir, I think it must be some sort of path issues...
but as soon as i ran the service with the local system and cheked interact
with desktop everything started running perfectly

"Mike" wrote:
>
How about running the service as the local system account and checking
"interact with desktop"?

"John Vottero" wrote:

"Noam" <No**@discussions.microsoft.comwrote in message
news:0C**********************************@microsof t.com...

[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.


Jul 5 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: BobHutch | last post by:
I am trying to create a windows service using vb.net to read a sql table every half hour and copy all new records created within each half hour increment to another table. I also want to be able...
4
by: Kavitha | last post by:
I am creating a windows service which sends email to some people at regular intervals. Shared Sub Main() Dim ServicesToRun As System.ServiceProcess.ServiceBase ServicesToRun = New...
3
by: Chris | last post by:
Hi, I need to create a windows service that will poll a database every 10 sec and print processed orders to a printer. Where can I find info on this? Thanks
1
by: NathanC | last post by:
I am trying to create a simple service since and have never done this before. I have created a new project in VB.NET that is a Windows Service. (Just writing a single event entry to the log, just...
3
by: Simon Harvey | last post by:
Hi all, What is the best way to catch any and all exceptions when creating a windows service application? Is there some sort of global exception event I can use, or is it possible to surround...
2
by: Diego F. | last post by:
I need to make a windows service that shows the process in a window. How can I add an interface to a windows service? -- Regards, Diego F.
2
by: =?Utf-8?B?U2Vhbk1hYw==?= | last post by:
I am familiar with how to use winsock in vb6 to create a network app. I'm trying to find a way to take the current vb6 app and create a windows service using system.net.sockets. How do you create...
1
by: Sheena777 | last post by:
How can I create a windows service to keep a program running with vb.net and visual studio. I have created a windows application that I have used the Onclick publish of visual studio 2005 and I now...
0
by: Harry Bellafonte | last post by:
Hi I have created a Windows Sesrvice through a reg file. This is the content of the reg file: Windows Registry Editor Version 5.00 "Description"="Starts the User Process."
0
vdraceil
by: vdraceil | last post by:
Can anyone explain how to make a windows service using vb6? I'm creating an application that will be running all the time.so instead of a exe, i prefer services. I know it is possible to make...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.