473,385 Members | 1,888 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,385 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 6784
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 start MySQL
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 2000. But I am seeing problems in Windows 2003...
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 console application and run the program everything...
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 database is running on a trail version on Linux...
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 customer doesn't configure it correctly, the service...
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 reasons for these to happen: i got a earlier...
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 first. However, after a few tests / connections, I...
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 possible options BUt the error is same.. See each...
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 file CreateDb.sql. I need to run it so that it...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.