473,396 Members | 2,140 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,396 software developers and data experts.

getting started with windows services

(1) I tried to use what seems like a standard line (from Walkthrough:
Creating a Windows Service Application in the Component Designer at
http://msdn2.microsoft.com/en-us/lib...t39148a.aspx):

if (!System.Diagnostics.EventLog.SourceExists("MySour ce")) { ...

But received this error when attempting to start the service:

System.Security.SecurityException was unhandled
Message: The source was not found, but some or all event logs could not
be searched. Inaccessible logs: Security.

(2) Per the walkthrough, I had set up the account on the
ServiceProcessInstaller to LocalService, which I assumed had insufficent
privilege. So I tried to recompile after setting this account to a
different choice. I then naively tried to install from the setup project
again, but got a message that the "service was marked for deletion" and I
needed to re-run the installer. But re-running gave the same message.

(3) I then tried to use "installutil /u MyNewService" to remove the
service outside of VS so I could re-install. But installutil did not
recognize the "/u" option! It just gave a list of "command/test/option
names". (This is on WinXP Pro.)

(4) So I re-launched VS and tried the installer again and this time it
installed successfully. But unfortunately, when I tried to start the
service, it produced the original error in (1) above.

Questions:
(A) Why am I getting a SecurityException and how can I get around it?
(B) What is the appropriate way to re-install a service?
(C) Why does installutil /u not work as advertised?
Oct 2 '06 #1
7 8400
This will probably be helpful. It has self installing capabilities.

Self-Updating Windows Service Infrastructure with Command Pattern Message
Queue Invoker Service

http://www.eggheadcafe.com/articles/20041204.asp

--
Robbe Morris - 2004-2006 Microsoft MVP C#
I've mapped the database to .NET class properties and methods to
implement an multi-layered object oriented environment for your
data access layer. Thus, you should rarely ever have to type the words
SqlCommand, SqlDataAdapter, or SqlConnection again.
http://www.eggheadcafe.com/articles/..._generator.asp

"michael sorens" <m_********@community.nospamwrote in message
news:op***************@spo-cont-2-dt.itron.com...
(1) I tried to use what seems like a standard line (from Walkthrough:
Creating a Windows Service Application in the Component Designer at
http://msdn2.microsoft.com/en-us/lib...t39148a.aspx):

if (!System.Diagnostics.EventLog.SourceExists("MySour ce")) { ...

But received this error when attempting to start the service:

System.Security.SecurityException was unhandled
Message: The source was not found, but some or all event logs could not
be searched. Inaccessible logs: Security.

(2) Per the walkthrough, I had set up the account on the
ServiceProcessInstaller to LocalService, which I assumed had insufficent
privilege. So I tried to recompile after setting this account to a
different choice. I then naively tried to install from the setup project
again, but got a message that the "service was marked for deletion" and I
needed to re-run the installer. But re-running gave the same message.

(3) I then tried to use "installutil /u MyNewService" to remove the
service outside of VS so I could re-install. But installutil did not
recognize the "/u" option! It just gave a list of "command/test/option
names". (This is on WinXP Pro.)

(4) So I re-launched VS and tried the installer again and this time it
installed successfully. But unfortunately, when I tried to start the
service, it produced the original error in (1) above.

Questions:
(A) Why am I getting a SecurityException and how can I get around it?
(B) What is the appropriate way to re-install a service?
(C) Why does installutil /u not work as advertised?

Oct 2 '06 #2
Hi Michael,

Since creating event log source requires administrative privilege, and it's
only needed to create once, I recommend you create the event log source in
the installer rather than in the service.

We can move the code to create the event log source from MyNewService to
ProjectInstaller:

public partial class MyNewService : ServiceBase
{
public MyNewService()
{
InitializeComponent();

eventLog1.Source = "MySource";
eventLog1.Log = "MyNewLog";
}

[RunInstaller(true)]
public partial class ProjectInstaller : Installer
{
public ProjectInstaller()
{
InitializeComponent();

if (!System.Diagnostics.EventLog.SourceExists("MySour ce"))
{
System.Diagnostics.EventLog.CreateEventSource("MyS ource",
"MyNewLog");
}

As the walkthrough mentioned, reinstalling the service on Windows 2000 will
needs rebooting since the service control manager will first disable the
service for deleting on reboot; for Windows xp and above, the windows
installer has some feature can reinstall the service without rebooting.
That's why you need to use the generated setup file to re-install the
service.

The installutil will need an assembly and install/uninstall the installers
inside the assembly. In this case, we don't need to use installutil
manually, since we've already created a setup project to call the installer
within the service assembly.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

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 3 '06 #3

"michael sorens" <m_********@community.nospamwrote in message
news:op***************@spo-cont-2-dt.itron.com...
| (1) I tried to use what seems like a standard line (from Walkthrough:
| Creating a Windows Service Application in the Component Designer at
| http://msdn2.microsoft.com/en-us/lib...t39148a.aspx):
|
| if (!System.Diagnostics.EventLog.SourceExists("MySour ce")) { ...
|
| But received this error when attempting to start the service:
|
| System.Security.SecurityException was unhandled
| Message: The source was not found, but some or all event logs could not
| be searched. Inaccessible logs: Security.
|
| (2) Per the walkthrough, I had set up the account on the
| ServiceProcessInstaller to LocalService, which I assumed had insufficent
| privilege. So I tried to recompile after setting this account to a
| different choice. I then naively tried to install from the setup project
| again, but got a message that the "service was marked for deletion" and I
| needed to re-run the installer. But re-running gave the same message.
|
| (3) I then tried to use "installutil /u MyNewService" to remove the
| service outside of VS so I could re-install. But installutil did not
| recognize the "/u" option! It just gave a list of "command/test/option
| names". (This is on WinXP Pro.)
|
| (4) So I re-launched VS and tried the installer again and this time it
| installed successfully. But unfortunately, when I tried to start the
| service, it produced the original error in (1) above.
|
| Questions:
| (A) Why am I getting a SecurityException and how can I get around it?
| (B) What is the appropriate way to re-install a service?
| (C) Why does installutil /u not work as advertised?

In order to help you out with this, we need to see more code.
if (!System.Diagnostics.EventLog.SourceExists("MySour ce")) { ...
is of little help as this line is not the cause of the exception, probably
what's inside the {... is.
Anyway, your problem is security related, notably a lack of registry
privileges. My guess is that you are trying to create a log, but the
LocalService account (a restricted account!) has no privileges to do so.
Creating logs from withing services is not advisable, you need to create the
log using a separate installer program or a simple script.
Willy.

Oct 3 '06 #4
As both Walter and Willy suggest that best practice dictates not to create
the event log within the service, I am fine with that. I was merely using
the sample code from Microsoft's primer. So I moved that couple lines of
code from Service1.cs to ProjectInstaller.cs as Walter showed. I then
opened the setup project context menu and selected Uninstall first, then
Install, which I am guessing is the better way to try re-installing. Upon
completion of the Install, my event log was created. (So I assume the
setup project automatically uses a higher privilege than what I set for
the Account property of the ServiceProcessInstaller, yes?) I then used the
ServerExplorer to locate the service, started it, and it successfully
added an entry in the new event log.

So I succeeded in getting my first service to execute properly, but I like
to understand my loose ends.
(4) Why does Microsoft's sample code fail on the security exception--is
that just a case of old code in the walkthrough? (And BTW, the exception
was indeed on the SourceExists method, and the text of the error message I
provided supports that. I had not even gotten to the creation of my new
log, which would most likely also throw a security exception...)
(5) And why does installUtil not work as advertised on my system?

Thanks to Walter and Willy for the good tip here. Thanks also to Robbe for
the intriguing article on managing services without stopping them--it is a
useful tool for serious applications.
Oct 3 '06 #5
Hi Michael,

(4) Yes the documentation is somewhat out-of-date.

(5) Previously I said it's no need to use installutil manually since we're
creating a setup which generates .msi file. That doesn't mean installutil
doesn't work as advertised. I just tested it again:

C:\projects\_All\MyNewService\bin\Debug>installuti l MyNewService.exe
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
Running a transacted installation.

Beginning the Install phase of the installation.
See the contents of the log file for the
C:\projects\_All\MyNewService\bin\Debug
\MyNewService.exe assembly's progress.
The file is located at
C:\projects\_All\MyNewService\bin\Debug\MyNewServi ce.Inst
allLog.
Installing assembly
'C:\projects\_All\MyNewService\bin\Debug\MyNewServ ice.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\projects\_All\MyNewService\bin\Debug\MyNewServi ce.exe
logfile = C:\projects\_All\MyNewService\bin\Debug\MyNewServi ce.InstallLog
Installing service MyNewService...
Service MyNewService has been successfully installed.
Creating EventLog source MyNewService in log Application...

The Install phase completed successfully, and the Commit phase is beginning.
See the contents of the log file for the
C:\projects\_All\MyNewService\bin\Debug
\MyNewService.exe assembly's progress.
The file is located at
C:\projects\_All\MyNewService\bin\Debug\MyNewServi ce.Inst
allLog.
Committing assembly
'C:\projects\_All\MyNewService\bin\Debug\MyNewServ ice.exe'.
Affected parameters are:
logtoconsole =
assemblypath = C:\projects\_All\MyNewService\bin\Debug\MyNewServi ce.exe
logfile = C:\projects\_All\MyNewService\bin\Debug\MyNewServi ce.InstallLog

The Commit phase completed successfully.

The transacted install has completed.

C:\projects\_All\MyNewService\bin\Debug>net start mynewservice
The MyNewService service is starting.
The MyNewService service was started successfully.
C:\projects\_All\MyNewService\bin\Debug>installuti l /u MyNewService.exe
Microsoft (R) .NET Framework Installation utility Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.

The uninstall is beginning.
See the contents of the log file for the
C:\projects\_All\MyNewService\bin\Debug
\MyNewService.exe assembly's progress.
The file is located at
C:\projects\_All\MyNewService\bin\Debug\MyNewServi ce.Inst
allLog.
Uninstalling assembly
'C:\projects\_All\MyNewService\bin\Debug\MyNewServ ice.exe'
Oct 5 '06 #6
Whether trying to install or uninstall, I get the same error from
installutil:
installutil MyNewService.exe
Error dispatching command/test named 'MyNewService.exe'

And I figured out why: my search path was picking up a *different* program
called 'installutil' (this one from Rational). Once I adjusted it, now I
get the .Net utility. Mystery solved.
Oct 9 '06 #7
Hi Michael,

Thank you for letting us know the cause.

Have a nice day!

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 10 '06 #8

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

Similar topics

6
by: Jeff Harbin | last post by:
I've spent the last 2 days trying to begin using mysql. I've purchased 3 books and read huge chunks of the documentation provided with the mysql zip file. I've downloaded...
10
by: Paul | last post by:
Hi I am trying to install vs.net and can install all of it except the web development section. It seems to require IIS(internet information server). I am running windows 2000 and do not have IIS...
1
by: bidalah | last post by:
Hello, I am looking for basic info on installing and using MSDE. I am trying to install and play with MSDE on my PC (Win2000). I finally managed to work my way through installation, and named...
3
by: George | last post by:
VS.NET 2002/VB I would like to begin learning about DB programming, and I'm not quite sure where to start. Before I add MSSQL 2000 to my hosting plan, the question that comes to mind is, how do...
1
by: BenS | last post by:
Good Morning and Happy Wednesday! I've got a web service that exposes a method that takes an string input parameter that specifies an executable on the server that starts a process. These...
2
by: cashdeskmac | last post by:
I have created and installed a Windows service which hosts a remote object for chat clients. The installation went fine, but when I try to start the service in the Services tool it says: "The...
2
by: Tina | last post by:
I'm trying to get started with Atlas and associated necessary javascript at the same time. I started out at http://atlas.asp.net/walkthroughs/gettingstarted/basic.net where they have an...
1
by: DFBrownnz | last post by:
Hi, Can anyone help get started on working with video files? I work in the financial services industry and wanted to try this on Windows XP with C++ .Net 2003. I want to add DRM (research...
33
by: JamesB | last post by:
I am writing a service that monitors when a particular app is started. Works, but I need to get the user who is currently logged in, and of course Environment.UserName returns the service logon...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.