472,342 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

Specifying A Service Specific Error...

I am sure this has been asked at least once before but I could not find
anything when searching.

If I set the value of the ExitCode property to 1066 for a windows service,
the text "A service specific error occured: 0." How do I (if it is possible)
change the value of the zero to something custom (like a "look in the event
log for further information" message)?

Thank you,

Jason Richmeier
Oct 18 '06 #1
4 6686
Hi Jason,

Based on my understanding, you want to show some customized error from your
.net Windows Service application. Since you are referring to ExitCode
property, I am assuming you are using VS2005. Thanks.

First, I am not sure where do you want to show the customized erorr. In
Windows Service architecture, there are 2 processes: service process and
SCP process(which proivdes UI to the user and communicates with the service
process through any IPC technologies). Defaultly, Windows provided a
general style of SCP application services.msc as a MMC, so we normally use
this services.msc to manipulate the service applications. So my question is
do you want to show the customized error in standard services.msc or your
own written SCP application? To write a customized SCP application, we may
leverage ServiceController .Net class, please see the article below for
details:
"Communicate With Windows Services"
http://msdn.microsoft.com/library/en...asp?frame=true

In my test project, I created a sample Windows Service application, with
the following simple code:
protected override void OnStop()
{
this.ExitCode = 100;
}

In services.msc, I clicked this deployed service and choose "Stop" command
to trigger the test code. The services.msc will report a dialog with the
error below:
"Error 100: Cannot create another system semaphore.". Is this what you
want? Note: the "Cannot create another system semaphore" string is the
win32 predefined error message for error code 100. So your application can
report any predefined win32 standard error through ExitCode property.

If you want to report something that is not specific to win32 predefined
error code, you should report it through
SERVICE_STATUS.dwServiceSpecificExitCode field.(Note: SERVICE_STATUS is a
win32 SDK C++ structure which is encapsulated in .Net service classes, you
can look it in MSDN for more information). However, there is one problem
of using SERVICE_STATUS.dwServiceSpecificExitCode field to report
customized failure:
"SERVICE_STATUS structure is encapsulated in .Net BCL, however, it is
marked as private and .Net did not provide any public property to
expose.(although .Net provide ExitCode property to expose
SERVICE_STATUS.dwWin32ExitCode field), so it is impossible for us to use
this field in .Net code."

For testing purpose, I use VS2005 to debug my test Windows Service process,
and set a breakpoint in OnStop() method. When the execution breaks in
OnStop() method, I use the "Watch Window" to view "this.status" field,
which contains .Net encapsulated SERVICE_STATUS structure. In this window,
I modified dwWin32ExitCode to 1066L(ERROR_SERVICE_SPECIFIC_ERROR) and
dwServiceSpecificExitCode to 100.(Yes, debugger can ignore the .Net
protection and change the memory directly)
I really will get the following dialog in services.msc:
"Windows could not stop the WindowsServiceErrorReport on local computer.
For more information, review the System Event log. If it is a non-Microsoft
serivce, contact the service vendor, and refer to service-specific error
code 100"

I also got an error message in eventlog below:
"The WindowsServiceErrorReport service terminated with service-specific
error 100 (0x64)."

So SERVICE_STATUS.dwServiceSpecificExitCode really meets our need, however
it is not exposed by current .Net FCL.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 19 '06 #2
Thank you for all of the information.

Based on the information you provided, I was able to make a call to the
Win32 SetServiceStatus call to specify the service specific exit code. It
took quite a bit of tinkering to get it to work (without error) but I think I
have finally got it working like I want.

Thank you,

Jason Richmeier

""Jeffrey Tan[MSFT]"" wrote:
Hi Jason,

Based on my understanding, you want to show some customized error from your
.net Windows Service application. Since you are referring to ExitCode
property, I am assuming you are using VS2005. Thanks.

First, I am not sure where do you want to show the customized erorr. In
Windows Service architecture, there are 2 processes: service process and
SCP process(which proivdes UI to the user and communicates with the service
process through any IPC technologies). Defaultly, Windows provided a
general style of SCP application services.msc as a MMC, so we normally use
this services.msc to manipulate the service applications. So my question is
do you want to show the customized error in standard services.msc or your
own written SCP application? To write a customized SCP application, we may
leverage ServiceController .Net class, please see the article below for
details:
"Communicate With Windows Services"
http://msdn.microsoft.com/library/en...asp?frame=true

In my test project, I created a sample Windows Service application, with
the following simple code:
protected override void OnStop()
{
this.ExitCode = 100;
}

In services.msc, I clicked this deployed service and choose "Stop" command
to trigger the test code. The services.msc will report a dialog with the
error below:
"Error 100: Cannot create another system semaphore.". Is this what you
want? Note: the "Cannot create another system semaphore" string is the
win32 predefined error message for error code 100. So your application can
report any predefined win32 standard error through ExitCode property.

If you want to report something that is not specific to win32 predefined
error code, you should report it through
SERVICE_STATUS.dwServiceSpecificExitCode field.(Note: SERVICE_STATUS is a
win32 SDK C++ structure which is encapsulated in .Net service classes, you
can look it in MSDN for more information). However, there is one problem
of using SERVICE_STATUS.dwServiceSpecificExitCode field to report
customized failure:
"SERVICE_STATUS structure is encapsulated in .Net BCL, however, it is
marked as private and .Net did not provide any public property to
expose.(although .Net provide ExitCode property to expose
SERVICE_STATUS.dwWin32ExitCode field), so it is impossible for us to use
this field in .Net code."

For testing purpose, I use VS2005 to debug my test Windows Service process,
and set a breakpoint in OnStop() method. When the execution breaks in
OnStop() method, I use the "Watch Window" to view "this.status" field,
which contains .Net encapsulated SERVICE_STATUS structure. In this window,
I modified dwWin32ExitCode to 1066L(ERROR_SERVICE_SPECIFIC_ERROR) and
dwServiceSpecificExitCode to 100.(Yes, debugger can ignore the .Net
protection and change the memory directly)
I really will get the following dialog in services.msc:
"Windows could not stop the WindowsServiceErrorReport on local computer.
For more information, review the System Event log. If it is a non-Microsoft
serivce, contact the service vendor, and refer to service-specific error
code 100"

I also got an error message in eventlog below:
"The WindowsServiceErrorReport service terminated with service-specific
error 100 (0x64)."

So SERVICE_STATUS.dwServiceSpecificExitCode really meets our need, however
it is not exposed by current .Net FCL.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 19 '06 #3
Hi Jason,

Yes, if I did not misunderstand you, you have declared a customized
SERVICE_STATUS structure in .Net and p/invoked SetServiceStatus to set the
dwServiceSpecificExitCode member for reporting error. Yes, I think this
will work.

It seems that my mind is blocked to believe that we must use the
SERVICE_STATUS structure stored in "ServiceBase.status" field for status
updating. This is not the case. We certainly can create a new
SERVICE_STATUS structure for SetServiceStatus API :-). Thank you for
pointing this out.

If you need further help, please feel free to post, thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 20 '06 #4
Additionally, you should write a customized SCP application to recognize
the service specific error reported by your service, since services.msc can
not understand such specific error.

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 20 '06 #5

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

Similar topics

2
by: jmlynn | last post by:
Help! I installed MySQL 4.0.20C and it works if I started it with mysqld --console However, if I do the following: mysqld --install net...
0
by: GTS | last post by:
Hi, I have created my application to run as windows service. It is developed using VC++ on Windows 2000 platform. It is working fine with Windows...
3
by: THNQDigital | last post by:
Hi All, I have written VB.NET Windows Service whcih reads some information from Outlook and creates an Excel report outa it. When i make a...
2
by: Madhu | last post by:
Hello All, I am getting the below error message when I am trying to connect from client to remote database server installed on Linux. DB2 UDB ESE...
6
by: Joe | last post by:
C# .NET 2.0 I've got a Windows Service that works exactly as I expect it to. However, it does rely on a few Configuration settings. If the...
2
by: maansi.creations | last post by:
Service unavailable error comes randomly while accessing our website and gets alright in matter of seconds....Could some one tell the possible...
2
by: Brent Halsey | last post by:
I am using the ibm_db2 PECL drive in PHP for connecting to or DB2 database. I created a persistent connection and things seemed to work fine at...
4
by: Pool | last post by:
I tried to connect DB2 (Sitting in Unix server at my client location) using Db2 connect V8. I am getting the following error message. I tried all the...
1
by: johnyjj2 | last post by:
Hello! I've got web application created for MSSQL and IIS. There are two directories in this application - Scripts and WebSite. In Script there is...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.