473,734 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FileN otFoundExceptio n 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.FileNot FoundException. 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 6528
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**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.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.FileN otFoundExceptio n 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.FileNot FoundException. 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.FileN otFoungExceptio n? 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**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.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.FileN otFoundExceptio n 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.FileNot FoundException. 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**@discussio ns.microsoft.co m> wrote in message
news:EC******** *************** ***********@mic rosoft.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.FileN otFoungExceptio n? 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**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.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.FileN otFoundExceptio n 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.FileNot FoundException. 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**@discussio ns.microsoft.co m> wrote in message
news:EC******** *************** ***********@mic rosoft.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.FileN otFoungExceptio n? 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**@discussio ns.microsoft.co m> wrote in message
news:EC******** *************** ***********@mic rosoft.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.FileN otFoungExceptio n? 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**@discussio ns.microsoft.co m> wrote in message
news:EC******** *************** ***********@mic rosoft.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.FileN otFoungExceptio n? 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**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.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.FileN otFoundExceptio n 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.FileNot FoundException. 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**@discussio ns.microsoft.co m> wrote in message
news:0C******** *************** ***********@mic rosoft.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\Syst em32
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.Environm ent.CurrentDire ctory.

Jun 20 '06 #10

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

Similar topics

3
388
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 to email each new record to a specific person. This system will need to run automatically. I know I can do this using an exe com component using windows scheduler to trigger the com componet, but I think that I can create the same type of...
4
1399
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 System.ServiceProcess.ServiceBase(){New MailService()} End Sub In Timer Elapsed Event: --------------------------------------------- Dim Mailmsg As New MailMessage()
3
2447
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
3306
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 to make sure it works) I have right-clicked in the designer and chosen Add Installer and modified the properties appropriately. I then added a Setup Project and built both solutions.
3
5989
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 the ServiceBase.Run(ServicesToRun); line with a try catch? Would that work?
2
5852
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
3598
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 a service (for the server side) that accepts incoming client connections using system.net.sockets? -- Sean McIntire
1
1388
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 need to convert the project to a windows service so that it will run continuosly with out having a user login to the windows XP. I have never worked with windows services before so have no clue as to how they work so any help will be appreciated thanks
0
1270
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
1639
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 services using vb,but i dont know how..somebody pls help
0
8776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.