473,386 Members | 1,908 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,386 software developers and data experts.

Service fails if user not logged in

A week or two ago I posted queries about retrieving user details about a
certain process and it all worked fine in the end, the service happily
reported when the required application was started/stopped and everyone was
happy.
A new problem has come to light though, that when someone turns on their PC,
my service isn't starting. Looking in the event log, I have the following
error:

Service cannot be started. System.Runtime.InteropServices.COMException
(0x80010002): Call was canceled by the message filter. (Exception from
HRESULT: 0x80010002 (RPC_E_CALL_CANCELED))
at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHRInternal(Int32
errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(O bject o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementEventWatcher.Initializ e()
at System.Management.ManagementEventWatcher.Start()
at MyService.ProcessInfo..ctor(String appName)
at MyService.NetviewerMonitor.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)

The code I have in my OnStart event is:

//Process object
private ProcessInfo nvProc;

protected override void OnStart(string[] args)
{
nvProc = new ProcessInfo("App_to_watch.exe");
nvProc.Started += new
ProcessInfo.StartedEventHandler(nvStarted);
nvProc.Terminated += new
ProcessInfo.TerminatedEventHandler(nvTerminated);
}
I am guessing the error is occurring because when the service starts no one
is logged in? This makes sense, because if a user starts the service
manually once they log in, it works perfectly. If so, any ideas what I can
do? I don't think sticking a try/catch block would help - it would stop the
error in event log, and the service would still run, but I doubt it would
work as the code to attach to the new process event wouldn't have fired, so
it would be chocolate teapot time... Can I put in some sort of block in my
OnStart to wait until a user is logged in? Seems a bit dodgy, as presumably
my service wouldn't show as started until the OnStart() completes and
Windows woud probably log errors to the effect of the service didn't start
within the timeout period...

Thanks.
James
Jun 15 '07 #1
4 8276
Hi,

Have you tried to use SystemAccount to run the process under?

"JamesB" <ja***@somewhere.com.net.com.netwrote in message
news:46***********************@news.zen.co.uk...
>A week or two ago I posted queries about retrieving user details about a
certain process and it all worked fine in the end, the service happily
reported when the required application was started/stopped and everyone was
happy.
A new problem has come to light though, that when someone turns on their
PC, my service isn't starting. Looking in the event log, I have the
following error:

Service cannot be started. System.Runtime.InteropServices.COMException
(0x80010002): Call was canceled by the message filter. (Exception from
HRESULT: 0x80010002 (RPC_E_CALL_CANCELED))
at
System.Runtime.InteropServices.Marshal.ThrowExcept ionForHRInternal(Int32
errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(O bject o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementEventWatcher.Initializ e()
at System.Management.ManagementEventWatcher.Start()
at MyService.ProcessInfo..ctor(String appName)
at MyService.NetviewerMonitor.OnStart(String[] args)
at System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)

The code I have in my OnStart event is:

//Process object
private ProcessInfo nvProc;

protected override void OnStart(string[] args)
{
nvProc = new ProcessInfo("App_to_watch.exe");
nvProc.Started += new
ProcessInfo.StartedEventHandler(nvStarted);
nvProc.Terminated += new
ProcessInfo.TerminatedEventHandler(nvTerminated);
}
I am guessing the error is occurring because when the service starts no
one is logged in? This makes sense, because if a user starts the service
manually once they log in, it works perfectly. If so, any ideas what I can
do? I don't think sticking a try/catch block would help - it would stop
the error in event log, and the service would still run, but I doubt it
would work as the code to attach to the new process event wouldn't have
fired, so it would be chocolate teapot time... Can I put in some sort of
block in my OnStart to wait until a user is logged in? Seems a bit dodgy,
as presumably my service wouldn't show as started until the OnStart()
completes and Windows woud probably log errors to the effect of the
service didn't start within the timeout period...

Thanks.
James


Jun 20 '07 #2

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Os**************@TK2MSFTNGP06.phx.gbl...
Hi,

Have you tried to use SystemAccount to run the process under?
Under the "LocalSystem" account, the code that retrieves the user of the
process I am watching always returns null, so it solves one problem but
creates another!

Jun 21 '07 #3
Hi,

"JamesB" <ja***@somewhere.com.net.com.netwrote in message
news:46***********************@news.zen.co.uk...
>
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Os**************@TK2MSFTNGP06.phx.gbl...
>Hi,

Have you tried to use SystemAccount to run the process under?

Under the "LocalSystem" account, the code that retrieves the user of the
process I am watching always returns null, so it solves one problem but
creates another!
The thing is that a Service is intended to be used as a background app. It
does start when the system start and at that moment there is no user logged
in.

You could try to use WMI and listen to events that might be fired when a
user login. But I do not know what events those are :)
Jun 21 '07 #4

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:uS**************@TK2MSFTNGP06.phx.gbl...
Hi,

"JamesB" <ja***@somewhere.com.net.com.netwrote in message
news:46***********************@news.zen.co.uk...
>>
"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote
in message news:Os**************@TK2MSFTNGP06.phx.gbl...
>>Hi,

Have you tried to use SystemAccount to run the process under?

Under the "LocalSystem" account, the code that retrieves the user of the
process I am watching always returns null, so it solves one problem but
creates another!

The thing is that a Service is intended to be used as a background app. It
does start when the system start and at that moment there is no user
logged in.

You could try to use WMI and listen to events that might be fired when a
user login. But I do not know what events those are :)
That's kinda where I got to, might have to do a rethink and actually deploy
it as a non-service app that simply starts when a user logs in (via a
reg-entry etc)

Thanks
James

Jun 21 '07 #5

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

Similar topics

3
by: Michael | last post by:
Hi, I have a windows service developed using c# and it needs to lunch another windows application. I have been trying to use Process class to do it but the problem is becase windows service...
3
by: Brad Jones | last post by:
Hello, I'm hoping someone can give me some help or guidance here. I'm not sure if this is even the best group to post to for this. Our OEM equipment's software architecture relies heavily on a...
7
by: Robert May | last post by:
I have an application that uses the Ax web browser object. When I call the IHTMLElement.click() method on an input button (<input type="submit"> or <input type="button">), the click fires...
23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
3
by: todd_groten | last post by:
Alright, I've been searching around for some time and have not been able to find anything concrete on fixing an issue I am having. Here's the situation: 1) I have a non-anonymous webservice...
2
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app...
3
by: Grant Schenck | last post by:
I have a simple remoting sample using IPCChannel. If I run the server code as a console app my client can connect just fine. However, if I the same server code runs in a service, the client gets...
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: dmihailescu | last post by:
the P/Invoke SetWindowLong failed with 'Access is denied' when invoked from a windows service. The service runs under the System account with the 'allow user to interact with the desktop' checked....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.