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

Windows Service with Microsoft Office PIA assembly

Hello,

I wrote a windows service application however it is not working. The
service is supposed to enter a new task every 5 sec within Microsoft
Outlook.

Here is the code for application:

public partial class CheckAccountsService : ServiceBase
{
private Timer timer = null;

public CheckAccountsService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
EventLog.WriteEntry("It is starting!!!!", "It is
starting!!");
System.Threading.Thread.Sleep(10000);
//Debug.Write("x");
// TODO: Add code here to start your service
timer.Enabled = true;
timer.Start();
createTestTask();
}

protected override void OnStop()
{}

public enum Importance
{
High = 0,
Normal = 1,
Low = 2
}

public static void createTestTask()
{
CreateOutlookTask("bla bla ", DateTime.Parse("6/6/2006 1:00
PM"), Importance.High, "bla bla");
}

public static void CreateOutlookTask(string Body, DateTime
dueDate, Importance Importance, string Subject)
{
// Create an Outlook Application object.
Application outLookApp = new Application();
// Create a new TaskItem.
TaskItem newTask =
(TaskItem)outLookApp.CreateItem(OlItemType.olTaskI tem);
// Configure the task at hand and save it.
newTask.Body = Body;
newTask.DueDate = dueDate;
switch (Importance)
{
case Importance.High:
newTask.Importance = OlImportance.olImportanceHigh;
break;
case Importance.Normal:
newTask.Importance =
OlImportance.olImportanceNormal;
break;
case Importance.Low:
newTask.Importance = OlImportance.olImportanceLow;
break;
}
newTask.ReminderSet = true;
newTask.ReminderTime = dueDate;
newTask.Subject = Subject;
newTask.Save();
}

private void ServiceTimer_Tick(object sender,
System.Timers.ElapsedEventArgs e)
{
this.timer.Stop();
createTestTask();
this.timer.Start();
}
}
I get the following errors :
********
Rejected Safe Mode action : Microsoft Office Outlook.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
********
AND
********
Service cannot be started. System.Runtime.InteropServices.COMException
(0x80080005): Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following
error: 80080005.
at AccountRemainder.CheckAccountsService.CreateOutloo kTask(String
Body, DateTime dueDate, Importance Importance, String Subject) in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
70
at AccountRemainder.CheckAccountsService.createTestTa sk() in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
55
at AccountRemainder.CheckAccountsService.OnStart(Stri ng[] args) in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
32
at
System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
********

Any idea ?

Jun 9 '06 #1
3 5854
If you try to access outlook from an external application (for sending
mail, etc, etc) it throws up a dialog asking if you want to allow the
action. My guess is that this would be the case here as well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<so****@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Hello,

I wrote a windows service application however it is not working. The
service is supposed to enter a new task every 5 sec within Microsoft
Outlook.

Here is the code for application:

public partial class CheckAccountsService : ServiceBase
{
private Timer timer = null;

public CheckAccountsService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
EventLog.WriteEntry("It is starting!!!!", "It is
starting!!");
System.Threading.Thread.Sleep(10000);
//Debug.Write("x");
// TODO: Add code here to start your service
timer.Enabled = true;
timer.Start();
createTestTask();
}

protected override void OnStop()
{}

public enum Importance
{
High = 0,
Normal = 1,
Low = 2
}

public static void createTestTask()
{
CreateOutlookTask("bla bla ", DateTime.Parse("6/6/2006 1:00
PM"), Importance.High, "bla bla");
}

public static void CreateOutlookTask(string Body, DateTime
dueDate, Importance Importance, string Subject)
{
// Create an Outlook Application object.
Application outLookApp = new Application();
// Create a new TaskItem.
TaskItem newTask =
(TaskItem)outLookApp.CreateItem(OlItemType.olTaskI tem);
// Configure the task at hand and save it.
newTask.Body = Body;
newTask.DueDate = dueDate;
switch (Importance)
{
case Importance.High:
newTask.Importance = OlImportance.olImportanceHigh;
break;
case Importance.Normal:
newTask.Importance =
OlImportance.olImportanceNormal;
break;
case Importance.Low:
newTask.Importance = OlImportance.olImportanceLow;
break;
}
newTask.ReminderSet = true;
newTask.ReminderTime = dueDate;
newTask.Subject = Subject;
newTask.Save();
}

private void ServiceTimer_Tick(object sender,
System.Timers.ElapsedEventArgs e)
{
this.timer.Stop();
createTestTask();
this.timer.Start();
}
}
I get the following errors :
********
Rejected Safe Mode action : Microsoft Office Outlook.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
********
AND
********
Service cannot be started. System.Runtime.InteropServices.COMException
(0x80080005): Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following
error: 80080005.
at AccountRemainder.CheckAccountsService.CreateOutloo kTask(String
Body, DateTime dueDate, Importance Importance, String Subject) in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
70
at AccountRemainder.CheckAccountsService.createTestTa sk() in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
55
at AccountRemainder.CheckAccountsService.OnStart(Stri ng[] args) in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
32
at
System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
********

Any idea ?

Jun 9 '06 #2
However I have tried it with windows forms application and it worked
fine. It gets complicated when I try to use the code to enter new
tasks in outlook from windows service application.

Nicholas Paldino [.NET/C# MVP] wrote:
If you try to access outlook from an external application (for sending
mail, etc, etc) it throws up a dialog asking if you want to allow the
action. My guess is that this would be the case here as well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<so****@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Hello,

I wrote a windows service application however it is not working. The
service is supposed to enter a new task every 5 sec within Microsoft
Outlook.

Here is the code for application:

public partial class CheckAccountsService : ServiceBase
{
private Timer timer = null;

public CheckAccountsService()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
EventLog.WriteEntry("It is starting!!!!", "It is
starting!!");
System.Threading.Thread.Sleep(10000);
//Debug.Write("x");
// TODO: Add code here to start your service
timer.Enabled = true;
timer.Start();
createTestTask();
}

protected override void OnStop()
{}

public enum Importance
{
High = 0,
Normal = 1,
Low = 2
}

public static void createTestTask()
{
CreateOutlookTask("bla bla ", DateTime.Parse("6/6/2006 1:00
PM"), Importance.High, "bla bla");
}

public static void CreateOutlookTask(string Body, DateTime
dueDate, Importance Importance, string Subject)
{
// Create an Outlook Application object.
Application outLookApp = new Application();
// Create a new TaskItem.
TaskItem newTask =
(TaskItem)outLookApp.CreateItem(OlItemType.olTaskI tem);
// Configure the task at hand and save it.
newTask.Body = Body;
newTask.DueDate = dueDate;
switch (Importance)
{
case Importance.High:
newTask.Importance = OlImportance.olImportanceHigh;
break;
case Importance.Normal:
newTask.Importance =
OlImportance.olImportanceNormal;
break;
case Importance.Low:
newTask.Importance = OlImportance.olImportanceLow;
break;
}
newTask.ReminderSet = true;
newTask.ReminderTime = dueDate;
newTask.Subject = Subject;
newTask.Save();
}

private void ServiceTimer_Tick(object sender,
System.Timers.ElapsedEventArgs e)
{
this.timer.Stop();
createTestTask();
this.timer.Start();
}
}
I get the following errors :
********
Rejected Safe Mode action : Microsoft Office Outlook.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
********
AND
********
Service cannot be started. System.Runtime.InteropServices.COMException
(0x80080005): Retrieving the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following
error: 80080005.
at AccountRemainder.CheckAccountsService.CreateOutloo kTask(String
Body, DateTime dueDate, Importance Importance, String Subject) in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
70
at AccountRemainder.CheckAccountsService.createTestTa sk() in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
55
at AccountRemainder.CheckAccountsService.OnStart(Stri ng[] args) in
C:\Documents and Settings\psokolowski\My Documents\Visual Studio
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
32
at
System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
state)

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
********

Any idea ?


Jun 9 '06 #3
There are a number of issues here, first of all, Office was not designed
(and is not supported) to be used from non interactive logon sessions, for
more info check this:
http://support.microsoft.com/default...b;en-us;257757
Your code fails because of COM security, that is, your service account has
no appropriate rights to start Outlook as COM automation server.

Second, you should not call Sleep in OnStart, the SCM will wait max. 30
seconds for OnStart to return before it considers the service has failed to
start successfully, I see no reason why you need to waste 10 seconds.
Third, you start a timer to call CreateOutlookTask, but at the same time you
call it from OnStart, what's the reasoning behind this?
Fourth, you don't have any error check/recovery in place, any exception
thrown on the thread running OnStart will abort the service, any exception
thrown on the timer thread will go unhandled.

Willy.
<so****@gmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
| Hello,
|
| I wrote a windows service application however it is not working. The
| service is supposed to enter a new task every 5 sec within Microsoft
| Outlook.
|
| Here is the code for application:
|
| public partial class CheckAccountsService : ServiceBase
| {
| private Timer timer = null;
|
| public CheckAccountsService()
| {
| InitializeComponent();
| }
|
| protected override void OnStart(string[] args)
| {
| EventLog.WriteEntry("It is starting!!!!", "It is
| starting!!");
| System.Threading.Thread.Sleep(10000);
| //Debug.Write("x");
| // TODO: Add code here to start your service
| timer.Enabled = true;
| timer.Start();
| createTestTask();
| }
|
| protected override void OnStop()
| {}
|
| public enum Importance
| {
| High = 0,
| Normal = 1,
| Low = 2
| }
|
| public static void createTestTask()
| {
| CreateOutlookTask("bla bla ", DateTime.Parse("6/6/2006 1:00
| PM"), Importance.High, "bla bla");
| }
|
| public static void CreateOutlookTask(string Body, DateTime
| dueDate, Importance Importance, string Subject)
| {
| // Create an Outlook Application object.
| Application outLookApp = new Application();
| // Create a new TaskItem.
| TaskItem newTask =
| (TaskItem)outLookApp.CreateItem(OlItemType.olTaskI tem);
| // Configure the task at hand and save it.
| newTask.Body = Body;
| newTask.DueDate = dueDate;
| switch (Importance)
| {
| case Importance.High:
| newTask.Importance = OlImportance.olImportanceHigh;
| break;
| case Importance.Normal:
| newTask.Importance =
| OlImportance.olImportanceNormal;
| break;
| case Importance.Low:
| newTask.Importance = OlImportance.olImportanceLow;
| break;
| }
| newTask.ReminderSet = true;
| newTask.ReminderTime = dueDate;
| newTask.Subject = Subject;
| newTask.Save();
| }
|
| private void ServiceTimer_Tick(object sender,
| System.Timers.ElapsedEventArgs e)
| {
| this.timer.Stop();
| createTestTask();
| this.timer.Start();
| }
| }
|
|
| I get the following errors :
| ********
| Rejected Safe Mode action : Microsoft Office Outlook.
|
| For more information, see Help and Support Center at
| http://go.microsoft.com/fwlink/events.asp.
| ********
| AND
| ********
| Service cannot be started. System.Runtime.InteropServices.COMException
| (0x80080005): Retrieving the COM class factory for component with CLSID
| {0006F03A-0000-0000-C000-000000000046} failed due to the following
| error: 80080005.
| at AccountRemainder.CheckAccountsService.CreateOutloo kTask(String
| Body, DateTime dueDate, Importance Importance, String Subject) in
| C:\Documents and Settings\psokolowski\My Documents\Visual Studio
|
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
| 70
| at AccountRemainder.CheckAccountsService.createTestTa sk() in
| C:\Documents and Settings\psokolowski\My Documents\Visual Studio
|
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
| 55
| at AccountRemainder.CheckAccountsService.OnStart(Stri ng[] args) in
| C:\Documents and Settings\psokolowski\My Documents\Visual Studio
|
2005\Projects\AccountRemainder\WindowsService1\Che ckAccountsService.cs:line
| 32
| at
| System.ServiceProcess.ServiceBase.ServiceQueuedMai nCallback(Object
| state)
|
| For more information, see Help and Support Center at
| http://go.microsoft.com/fwlink/events.asp.
| ********
|
| Any idea ?
|
Jun 9 '06 #4

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

Similar topics

2
by: Mark | last post by:
I created an extremely simple windows service that only writes to the EventLogs on Stop and Pause. I installed it using the InstallUtil.exe program, the output of which is below. It appears to be...
0
by: W Akthar | last post by:
Hi All, I have created a simple Windows Service which needs to be able to send appointments to Outlook. I have no problem makeing a reference to Microsoft Outlook 11.0 Object Library and...
6
by: Nathan Kovac | last post by:
Yesterday afternoon I was getting the following errors in a windows service: 'DatabaseManager.DataComponent', 'Error', '3 Errors: Line: 0 - Metadata file 'ScriptingMethods.dll' could not be found...
11
by: tshad | last post by:
I have a small Windows Service program that just has a timer on it and it built fine. I try to install it using InstallUtil and I get the following message: ...
7
by: Larry Bird | last post by:
I have a windows service that want to un-install. When I run "installutil /u serivcename" I get the error that the serivce is not installed on my machine. However, when view the serivce console I...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
7
by: michael sorens | last post by:
(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/library/zt39148a.aspx): ...
0
by: pratika2002 | last post by:
Hi, I am having a windows service project which is built by someone else and I have to understand the fuctionality. While running the service I am getting the following exception. "An unhandled...
16
emibt08
by: emibt08 | last post by:
Hello fellow programmers. I am working on a project that is a windows service. It should open an excel file and read it and it worked good on WinXP SP2 w/ Office 2003. Now the customer upgraded to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.