CreateProcess fails in windows service

I'm creating a windows service using visual studio .Net. I have a
server program that handles some network messages. I want to create a
service that runs this server program when the computer starts. The
program does have a UI, but I don't care about the UI (it does what I
need it to do without any UI updating). In the OnStart() function, I
basically have a call to CreateProcess() that runs my server.

The service seemed to install fine. When I try to start the service in
the visual studio Server Explorer, however, I get this error message:

Couldn't perform the requested operation for service "TestService" on
Machine "MyComp"".

I didn't know of any other way to validate my code, so I tried to
replace my the server program ("Server.exe") in the code with
"notepad.exe". That worked fine (CreatProcess returned successfully and
I had no problems starting the service). Changing it back to
"server.exe", however, gives that error message and it doesn't even
seem to finish OnStart().

There is an error written to the log file under "Event
Logs/Application" (the one that normally says "Service stopped
successfully..." and "Service started successfully..."):

Service cannot be started. System.NullReferenceException: Object
reference not set to an instance of an object.
   at CreateProcessW(UInt16* , UInt16* , _SECURITY_ATTRIBUTES* ,
_SECURITY_ATTRIBUTES* , Int32 , UInt32 , Void* , UInt16* ,
_STARTUPINFOW* , _PROCESS_INFORMATION* )
   at TestService.TestServiceWinService.OnStart(String[] args) in
d:\tools\testservice\testservicewinservice.h:line 66
   at
System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object
state)

I have no idea what this means.

This is my first time trying to create a service, so I have no idea if
I'm even pursuing the right path with this. Any help is appreciated.

Thanks,
Duy Lam


Here is the relevant CreateProcess() code in the OnStart() function
(again, replacing "server.exe" with "notepad.exe" works so I don't know
what's the problem):

PROCESS_INFORMATION Pi;			ZeroMemory(&Pi,sizeof(PROCESS_INFORMATION));

STARTUPINFO si;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);

if (!CreateProcess(NULL, _T("D:\\Server.exe"), NULL, NULL, FALSE, 0,
NULL, NULL, &si, &Pi)) {
  // some logging stuff here
}

0
duylam1 (4)
2/22/2006 12:27:20 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1139 Views

Similar Articles

[PageSpeed] 0

Services generally runs under the LocalSystem Account. If your service runs 
under LocalSystem Account, then you will not be able to do networking unless 
you change the account in which the service runs.

-- 
Cheers
Check Abdoul
------------------


"Duy Lam" <duylam@gmail.com> wrote in message 
news:1140568040.478855.118590@z14g2000cwz.googlegroups.com...
> I'm creating a windows service using visual studio .Net. I have a
> server program that handles some network messages. I want to create a
> service that runs this server program when the computer starts. The
> program does have a UI, but I don't care about the UI (it does what I
> need it to do without any UI updating). In the OnStart() function, I
> basically have a call to CreateProcess() that runs my server.
>
> The service seemed to install fine. When I try to start the service in
> the visual studio Server Explorer, however, I get this error message:
>
> Couldn't perform the requested operation for service "TestService" on
> Machine "MyComp"".
>
> I didn't know of any other way to validate my code, so I tried to
> replace my the server program ("Server.exe") in the code with
> "notepad.exe". That worked fine (CreatProcess returned successfully and
> I had no problems starting the service). Changing it back to
> "server.exe", however, gives that error message and it doesn't even
> seem to finish OnStart().
>
> There is an error written to the log file under "Event
> Logs/Application" (the one that normally says "Service stopped
> successfully..." and "Service started successfully..."):
>
> Service cannot be started. System.NullReferenceException: Object
> reference not set to an instance of an object.
>   at CreateProcessW(UInt16* , UInt16* , _SECURITY_ATTRIBUTES* ,
> _SECURITY_ATTRIBUTES* , Int32 , UInt32 , Void* , UInt16* ,
> _STARTUPINFOW* , _PROCESS_INFORMATION* )
>   at TestService.TestServiceWinService.OnStart(String[] args) in
> d:\tools\testservice\testservicewinservice.h:line 66
>   at
> System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object
> state)
>
> I have no idea what this means.
>
> This is my first time trying to create a service, so I have no idea if
> I'm even pursuing the right path with this. Any help is appreciated.
>
> Thanks,
> Duy Lam
>
>
> Here is the relevant CreateProcess() code in the OnStart() function
> (again, replacing "server.exe" with "notepad.exe" works so I don't know
> what's the problem):
>
> PROCESS_INFORMATION Pi; ZeroMemory(&Pi,sizeof(PROCESS_INFORMATION));
>
> STARTUPINFO si;
> ZeroMemory(&si, sizeof(STARTUPINFO));
> si.cb = sizeof(STARTUPINFO);
>
> if (!CreateProcess(NULL, _T("D:\\Server.exe"), NULL, NULL, FALSE, 0,
> NULL, NULL, &si, &Pi)) {
>  // some logging stuff here
> }
> 


0
CheckAbdoul
2/22/2006 3:08:01 AM
I'm having a similar problem, could you please post your solution? I'd
love to see the notepad.exe version, as I can't make it work, even
though it does work in a standard application.

Thanks, Rasmus



--
rasmus
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------
 
0
6/19/2007 1:10:35 PM
The original message seems to have not made the newsgroup.

However, note that firing off a gui app from a service doesn't usually make sense, since
there is no place for it to communicate to.
					joe

On Tue, 19 Jun 2007 08:10:35 -0500, rasmus <rasmus.2sfeau@mail.codecomments.com> wrote:

>
>I'm having a similar problem, could you please post your solution? I'd
>love to see the notepad.exe version, as I can't make it work, even
>though it does work in a standard application.
>
>Thanks, Rasmus
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
6/19/2007 3:17:48 PM
1. try to set for service property/checkbox
"Allow service to interact with desktop"
2. startup service under other account

rasmus wrote:
> I'm having a similar problem, could you please post your solution? I'd
> love to see the notepad.exe version, as I can't make it work, even
> though it does work in a standard application.
> 
> Thanks, Rasmus
> 
> 
> 
> --
> rasmus
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>  
0
at1970 (4)
6/22/2007 2:44:56 PM
Reply:

Similar Artilces:

How to reinstall or repair Windows Media Player 11
My Windows Media Player 11 is broken. It sounds horrible. The sound is garbled and no amount of adjustments change this. Previous attempts to get help fixing this have been unsuccessful. And now, if I burn MP3s with it, to a CD, the CD will not play in stand-alone players. It gives a No Disc message, though I can see that the disc has been burned. So... How about uninstalling it then reinstalling? Repairing it? Rolling back to an older version? I found these instructions: http://www.microsoft.com/windows/windowsmedia/player/11/readme.aspx#RollingbacktoapreviousversionofthePl...

office 2003 w/ windows 7 requires reacceptance ot T&C's each time
office 2003 w/ windows 7 requires reacceptance of T&C's each time i open work or excell or any office program. How do I get rid of this? Boot into Safe mode in Windows 7,open any Office app and then accept the terms -- Peter Please Reply to Newsgroup for the benefit of others Requests for assistance by email can not and will not be acknowledged. "mouser830" <mouser830@discussions.microsoft.com> wrote in message news:E7B7602D-F5D8-4559-98EF-A2CCC1E2D6FD@microsoft.com... > office 2003 w/ windows 7 requires reacceptance of T&C's each time i op...

Re: Update for Windows Vista (KB980248) -- No more fonts available!
cf. http://social.answers.microsoft.com/Forums/en-US/vistawu/thread/f7fa37ca-683c-4be1-b4ad-ab2dd1249399 PA Bear [MS MVP] wrote: > Are you running Vista SP1 or Vista SP2? Is Office 2010 installed? > > Was KB980248 offered & eventually installed via Windows Update or did you > (attempt to) install it manually? > > What anti-virus application or security suite is installed and is your > subscription current? What anti-spyware applications (other than > Defender)? > What third-party firewall (if any)? > > Has a(another) Norton or McAfee ap...

Need online services to the end of the year
I have been a loyal Money customer for years. This morning my Money Plus subscription expired. There seems to be no way to extend it and without it I can't do updates from my bank and credit cards--which I do daily. I understand that everything is shutting down by Jan 11, but it is terrible not to be able to extend basic online services temporarily at least through the end of this year to get me through tax season, etc. and then switch to Quicken at the beginning of 2010. This really sucks! Please, please Microsoft give us at least a stay of exectution through the end of the ye...

Check correction patch for Microsoft Windows
--jgfiyombh Content-Type: multipart/related; boundary="kgqnlddpakhbjo"; type="multipart/alternative" --kgqnlddpakhbjo Content-Type: multipart/alternative; boundary="pdizbrrdstws" --pdizbrrdstws Content-Type: text/plain Content-Transfer-Encoding: quoted-printable MS Consumer this is the latest version of security update, the "October 2003, Cumulative Patch" update which resolves all known security vulnerabilities affecting MS Internet Explorer, MS Outlook and MS Outlook Express as well as three new vulnerabilities. Install now to maintain the securit...

Operating a small passenger service
I am hoping someone has managed to customise outlook in a way that allows you to use the programe to manage bookings on a small passenger service. I.e input a new booking, number of people, location etc. Then email the days bookings to the different drivers. Maybe it could also be set up to know how many seats are avialale to reduce the risk of double booking? Im using Outlook 2003. ...

SMTP service stalled
Hi, We're running Exchange 2003 SP2 on Windows 2003 R2 which doubles as a secondary domain controller. We are periodically running into an issue where e-mail is not able to come in or go out and attempting to restart the SMTP service results in an error that the service did not respond in a timely manner. Rebooting the server fixes the problem temporarily until it occurs again, usually several days later. I'm assuming it's a memory issue, but the performance monitor shows that there is a minimal amount of memory in use (4 GB total, 3 GB free). Once service is restored it ca...

Reminder window doesn't pop up
When a reminder reaches the time to remind me, I hear a sound, and the reminders windows flashes on the task bar, but it does not pop up a window in front of me, whether or not I am using the mouse or keyboard at the time. Is there a setting for this? How do I make it pop up as it used to on my older system as I am missing out on these reminders which occur when my back is turned, or I have stepped awa from my desk? WinXPPro and Outlook 2003. Thanks, Mich What add-ins do you have running in Outlook? IIRC, one of them, Plaxo I think, causes reminder windows to pop up behind the ac...

Reporting Services not installed
Hi all, I have installed crm and reporting services but when I go into a report, display it and then hit print I get an popup box saying.... "Do you want to install this software? Name: Microsoft SQL Server Reporting Services" Can anyone help please Thanks Jools There's an ActiveX control each client machine needs in order to print SQL Reports from CRM. It's a one-time 5-second install. -- Matt Wittemann, CRM MVP http://icu-mscrm.blogspot.com "Jools" wrote: > Hi all, > > I have installed crm and reporting services but when I go into a report, ...

SDI: Switching between main SDI app windows
I want to be able to allow the end-user to pick between medium and large font sizes for the various controls on the main SDI application window. This windows has several radio-button-groups, a CTreeCtrl, and a CRichEditCtrl. When I use the form editor to lay out the main SDI app window, I'm now using Arial 8. If I change the Properties for the entire window to something larger (like Arial 10 or 14), then all the controls have the font-size increased, and the controls themselves get bigger. This seems like an easier approach than changing the font size for each control, and figuri...

ATTENTION: Windows CE Embedded Live Chat Tomorrow
Just a note that we'll be hosting an online chat tomorrow concerning Windows Embedded CE! Members of the development team will be on hand ready to answer your questions, so bring 'em on! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Title: Windows CE Live Chat! Tuesday, March 30th, 2010 9:00 - 10:00 A.M. Pacific Time Additional Time Zones: http://www.timeanddate.com/worldclock/fixedtime.html?month=9&day=30&year=2008&hour=9&min=0&sec=0&p1=234 Description: Do you have tough technical questions regarding Windows CE for which you're seeking ...

Windows 7 and Dynamics GP 10 SP1
We are on Dynamics GP 10.0 SP1. We have many users that want to upgrade to Windows 7, but we are not ready to upgrade Dynamics. Does anyone know of a way to install Dynamics GP 10 SP1 on a Windows 7 machine? I was told there is a Feature Pack 1 that will allow the install, but it appears to me that you have to have SP4 installed before you can install the feature pack. Thanks GP has a DVD image available that you can install. They had many problems with the .net 2.0 sp1 so that GP could not be installed (easily) on any machine that had .net 2.0 sp1. They created a new insta...

XP Look and Feel in Windows 2000 using ComCtrl32.dll
Hai I Want to have a XP Look and feel under windows2000 using VC++ and ComCtrl32.dll and does any one have any idea please help me as basically iam looking to develop a Skin Waiting for your reply suresh You will have to draw many of your own components. You could purchase a library like the one from www.codejock.com or www.dundas.com or or www.bcgsoft.com use something like this: These are for Office XP, but you'll get the idea. It's a ton of work: http://www.codeproject.com/miscctrl/officexp.asp Tom "suresh" <s...

Can I create a CScrollView popup window?
Hi, My application displays video from a firewire camera. The video is displayed in a CScrollView derived window that I create in CMainFrame::OnCreate() like this: m_pImageView = new CImageView; m_pImageView->Create(NULL, NULL, WS_CHILD | WS_VISIBLE, rClient, this, AFX_IDW_PANE_FIRST, NULL)) Now, when the user stops the video, they can click a toolbar button that pops up a CWnd derived window that displays all of the image data on a particular line of video. So, if the camera is spewing out 8-bits per pixel in the 800x600 mode, the popup window would display the 800 bytes associated w...

Windows Vista is it worth it?
Can I have thoughts regarding Vista, is it all better, than previous versions of MS Windows? "Christopher Henson" <chris21192@msn.com> wrote in message news:u8%23ZpRNCIHA.5600@TK2MSFTNGP04.phx.gbl... > Can I have thoughts regarding Vista, is it all better, than previous > versions of MS Windows? It is far more secure than earlier versions of Windows, but this is not the place to discuss Vista, or Windows subject matter. Your question may be better answered in a newsgroup appropriate to your problem. This newsgroup is dedicated to the Microsoft Access database p...

Service Packs & Updates
I have used the trial software from Microsofts site of SBS 2008 which is SP1 I have done all updates but it hasnt gone to SP2 should I do this manually?? Also as its a trial I was just going to purchase Lic and add key is this OK or should I pruchase Media and resetup again? Any Advice would be appreciated Thanks - Mark I've had problems installing SP2 in the past too. You've really got to do all the Updates and restart and then check again ......and again.. It'll only offer SP2 when *all* the other Updates have been installed. Have you switched to get...

Services Invoices Get "DROP SHIP" box checked Automatically
This is a multi-part message in MIME format. ------=_NextPart_000_000A_01CA45AC.F9A0B1F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hello Everybody, Here is another story. we are GP 10 SP3 and we also a Field Service (Depot Module) installed = for which we use an Invoice ( SVC000000) and our type is Service type = Invoice. At the time of posting the Service Charges being generated by the Depot = Module, the Drop ship box gets checked automatically for which we can't = charge the customer for shipping charges. Basically we eve...

Windows Live Calendar 01-28-10
Is there a way I can send one URL and allow access to a family member for ALL five of my calendars as I see it in Windows Live? ...

Scrolling splitter windows via keyboard
I want to be able to scroll the views in a vertical splitter window (synchronized) in response to the UP, DOWN, PAGEUP, PAGEDOWN keys. How can this be achieved? I set up the scroll sizes by calling SetScrollSizes in OnInitialUpdate() and then handle the OnKeyDown message in the view of the splitter window. In the OnKeyDown function, I tried calling OnVScroll(), but it does not work!! Can someone please help? Thank you Abhijit Abhijit, You might perhaps want to try calling ScrollToPosition instead of OnVScroll. Johan Rosengren Abstrakt Mekanik AB "Abhijit" <abhijit_patait_N...

Run Time Error 3151: ODBC Connection Failed
I converted an ACCESS 97 db to ACCESS 2000. I have some link tables uses ODBC DSN to connet to Oracle db. After the conversion, I refered the DAO 3.6 instead of default ADO and I checked the syntax, it has no compling errors. I also took off the ADO from the reference to make sure it is not using ADO. But I kept on getting the run time error 3151: ODBC connection to the DSN failed when I open the current db and then some recordset and call another function in which it opens the currentdb and then open recordset too. I think the problem related to open mutiple recordsets under current...

Windows Services #3
I want to provide a windows service. And then I want to write an application so that interact with this windows service. notice: I want to do these work in C++6.0 not in .NET Framework -- Mojtaba ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------ ...

Outlook 2003 access to Hamster IMAP fails
I was using Outlook 2003 with Hamster Classic 2.0.0.1 Everything was fine until the Microsoft update 2 weeks ago. When I closed Outlook the processor went to 100%. This seems to be a know bug of Hamster 2.0.0.1 based on pasts posts to the Hamster newsgroup. I therefore upgraded Hamster to 2.1.0.11. Now Outlook 2003 continually locks up. There are no problems with Outlook 2002 or any other email client including Thunderbird and Outlook Express. The issue is limited to Outlook 2003. The older version of Hamster did not support IDLE. I believe the problem is connected to IDLE. Is there a w...

Installation CRM 1.2 on SBS2003 SP1 fails, please help
At the end of my installation I get an error windows with; Setup was unable to install Microsoft CRM Server Setup was unable to provision your organisation Setup was unable to create user settings. Access is denied. (80070005) Active Directory is in native mode I am installing as the administrator (domain admin) security account for services in Local System account Local System account and computer are added to the Pre Windows 2000 comp group Thanks in advance for any support Marc Did you enter your organization name precisely the same way it appears on your CRM 1.2 licenses? -- Matt ...

550 Sender verify failed?
This is a multi-part message in MIME format. ------=_NextPart_000_00C3_01C49B43.ADE4BEA0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable I have a problem with some emails, return: The recipient name is not recognized 550 Sender verify failed Exchange 5.5 (NT 4.0) works fine with hotmail, yahoo, etc. any ideas? thanks, Jose Orlando ------=_NextPart_000_00C3_01C49B43.ADE4BEA0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transiti...

Group Exchange Services
Windows 2003 server and Exchange 2003 sp1 Is group "Exchange services" a relevant group for Exchange 2003 and windows 2003? Thanks Stefan Hello: That group is relevant to Exchange and should not be modified. IIRC, it is created after installing your first Exchange server. Regards, Martin "StefanHammar" <StefanHammar@discussions.microsoft.com> wrote in message news:F5C43401-7DA4-4E19-B2F6-288DA052AF7A@microsoft.com... > Windows 2003 server and Exchange 2003 sp1 > > Is group "Exchange services" a relevant group for Exchange 2003 and > win...