473,750 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service accessing Excel file :(

emibt08
25 New Member
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 Windows Vista 32-bit w/ Office 2007 and keep getting the following error:
--------------------------------------------------------------------------------------------------
SOURCE: Microsoft Office Excel
MESSAGE: Microsoft Office Excel cannot access the file 'C:\ProgramData \DataProcApplic ation\DataFile. xls'. There are several possible reasons:

• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
--------------------------------------------------------------------------------------------------

i made sure the file exist and is in the correct folder. I gave admin privileges to the file and the folder, i run the service as admin and nothing seems to work. Now, i am sure the problem isn't in the file itself, since it's there. I also save some other binary files in that folder which the service can read/write to. As i assigned admin privileges, i can successfully read/write to a file in another path (not just isolated storage) like c:\somefile.txt .
So, i'm pretty sure the problem is with the excel interop, just cant really get it. This is the function that throws exception:

Expand|Select|Wrap|Line Numbers
  1. Workbook wb =
  2.                 excelApp.Workbooks.Open(
  3.                     path,
  4.                     2,      // UpdateLinks 1, 2, 3
  5.                     true,   // True to open the workbook in read-only mode.
  6.                     1,      // If Microsoft Excel is opening a text file, this argument specifies the delimiter character, as shown in the following table. If this argument is omitted, the current delimiter is used.
  7.                     null,   // Password string
  8.                     null,   // WriteResPassword string
  9.                     true,   // IgnoreReadOnlyRecommended
  10.                     XlPlatform.xlWindows,   // Origin
  11.                     ";",    // Delimiter
  12.                     false,  // Editable for add ins?
  13.                     false,  // Notify
  14.                     1,      // Converter ???
  15.                     false,  // AddToMru
  16.                     true,   // Local
  17.                     Microsoft.Office.Interop.Excel.XlCorruptLoad.xlNormalLoad); // CorruptLoad
  18.  
I've been trying to solve this all day long and trying to find a solution online with no luck. I saw posts with the same question though, but no answer. So, if anyone have a solution for this, please help me out.

Any help is greatly appreciated.
Cheers
Nov 17 '08 #1
16 34153
balabaster
797 Recognized Expert Contributor
I think the issue is likely that you are trying to open an Excel 2007 workbook using an older workbook object - i.e. from Excel 2003. It's not possible to open an xlsx file using the older Excel objects. You need to update your application references to point to the new Excel 2007 objects. In order to do this, the application will need to be compiled on a machine that either has Excel 2007 installed or has the correct DLL loaded onto it...
Nov 17 '08 #2
emibt08
25 New Member
I think the issue is likely that you are trying to open an Excel 2007 workbook using an older workbook object - i.e. from Excel 2003. It's not possible to open an xlsx file using the older Excel objects. You need to update your application references to point to the new Excel 2007 objects. In order to do this, the application will need to be compiled on a machine that either has Excel 2007 installed or has the correct DLL loaded onto it...
Thanks for the reply balabaster, but that is not the problem. If you see the code, you can see that i am opening an excel 2003 workbook (xls file). However, i have updated the references to interop with Excel 2007, as i have Office 2007. Before the error started to show up, the service was running on Windows XP SP2 with Office 2003 with no problems and later on Windows XP SP3 with Office 2007. There were no problems with those systems. Once the OS was changed to Windows Vista 32-bit with Office 2007 the error came up. The references have been updated ever since the service was deployed at a system with Office 2007 and was working flawlessly. So, my guess is that it has something to do with Vista. However, as i said on internet i see the same question on many sites and forums. But i see no answer though :(
Nov 18 '08 #3
balabaster
797 Recognized Expert Contributor
Hmm... with this service, when you upgraded to Vista - did you make sure the service itself still has permission to interact with the desktop?
Nov 18 '08 #4
emibt08
25 New Member
Hmm... with this service, when you upgraded to Vista - did you make sure the service itself still has permission to interact with the desktop?
Thanks for the reply. But again no luck. I haven't set that though and i did with checking that options in the Administration tools -> Services before messing with the registry and ServiceInstalle r options. But i don't think it would help anyway since it's different in Vista. But i tried anyways. Then i created a console application that would do all of the Excel-related work. I called that app from another console and GUI app to check it out and everything if fine. But once i opened it from the service... again no luck. The same error message:

Exception: Microsoft Office Excel cannot access the file 'C:\TestExcelFi les\TestBook1.x ls'. There are several possible reasons:

• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.

Then i called that console app with CreateProcessAs User to elevate some privileges and impersonate and again the same error (although i got a console window this time, which i don't need anyway).
So, i've been working on this issue for about 2-h straight and i'll keep up until it's solved, it just drives me nuts.

Please, if anyone has any suggestion about this post me.
Nov 18 '08 #5
davidnelson
4 New Member
Any resolution on this? I am having the same problem.
Jan 8 '09 #6
MasterEvilAce
2 New Member
Wondering if you have solved this issue yet.

Unsure of vista specifically... but my research shows that automation is an issue with Windows Server 2008, specifically the 64-bit version.
The 32bit version works, as well as windows 2003 32/64bit.
I'm unsure as to whether it affects only SERVICES or APPLICATION automation as well..
We use a service for our tasks.

Recently we have run into this problem, and it's pretty important. We do some high dollar work using excel automation, and have recently obtained a new system running windows server 2008, just to find out there seems to be a bug/issue that prevents our application from doing its core work.
We get the same issue... excel loads, you go to open a workbook, and it errors out. Would appear to be a security / permissions bug, but have tried running under numerous accounts that have access to the file, and nothing.

If you have found a solution please let me know.
Jan 9 '09 #7
PRR
750 Recognized Expert Contributor
Try the following
1. Install your service using latest version of installutil..." \WINDOWS\Micros oft.NET\Framewo rk\version"
2. Try installing the following ....Download details: 2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies
3. Check on "MasterEvil Ace" tip .. "my research shows that automation is an issue with Windows Server 2008, specifically the 64-bit version"
4. Finally ...Office automation is not recommended.... .MS Office requires active user and start as interactive process... Also see if the office components are "initialize d" when you are tryin to automate opening excel file... There may be some dependency.... Make sure some user has already logged in?
Also check on vista service account : session 0 thing....from what i know vista services run under Session 0.... session 0 does not have access to graphics or UI....
Also try explicitly giving file system rights n other rights to your service....

Let us know if you find the solution .....
Jan 10 '09 #8
davidnelson
4 New Member
vote down


I have "kind of" solved this problem. If you use "dcomcnfg" to change the account to launch the excel application to a user account or "interactiv e user" the excel launched from the service starts in that account and it now can access the file system.

The problem is this is a global setting. If you use: * "this User": then excel ALWAYS opens with that user AND always opens up with no UI in session 0, even for interactive use of excel. IE its always invisible. * "Interactiv e User": Now excel always launches in the interactive user accout which I don't think will work for a service which will launch on bootup with NO interactive user.

There must be some security setting on this. I hope others have other ideas.
Jan 10 '09 #9
emibt08
25 New Member
I kind of get a little frustrated with this kind of problem while working on a solution. Besides, there was not really any pointer to the right direction, and i needed the solution fast. So, i still believe it's a Vista issue, just didn't have enough time to spend on this issue.
However, this is how i solved it and made it work. I made another small application which would do all Office (read Excel) related stuff. Then, i spawn that application in the isolated storage of my service and communicate to it through named pipes (although i could use other methods of IPC). And then i just pass parameters to it and get results from it. So, the problem is definitely related to the service, not the user not having enough permissions etc. And since the service is starting/stopping the other application, it runs under the same user account as the service, just it's not a service. However, the issue might be due to the fact pointed out by DeepBlue, that the services in Vista run under session 0.
However, i don't exclude the possibility that it might be another M$ bug. Just need some time to do more research on the subject, but with the everchanging security models in Windows i don't even know if it's worth it. And then, is it gonna run on Windows 7, or maybe when it comes out and my customers upgrade will call to let me know that it again stopped working. It's just a real mess. Sometimes i wish that the Raymond Chen camp have won the battle inside M$. At least we would have the backward compatibility.

Cheers
Jan 20 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1584
by: Stephan Lux | last post by:
Hi all, I have developed a windows service with Visual Basic .NET which starts a file conversion tool via the commandline. The tool open the files (z.B. Word, Excel, Acrobat...) and prints them over an image printer driver to tiff-files. On my Windows XP client it works fine, but on the target system (Windows 2003 Server) some issues occured: My first release uses the framework process class to start the application. As a standalone...
2
30577
by: Kumar | last post by:
Hi Folks, I have a question regarding my windows c# application. This application just reads MS Excel file and puts the data in to sql server database. In that excel file ,it has one named cell as "OutputStampTime". I am facing problem while accessing this cell value. When I open excel, I can see the value as "6:49 AM" . But when I click on that cell in the formula bar I am seeing as 01/27/2005 06:49:47 AM.
4
2018
by: Lenard Gunda | last post by:
Hello! I have created a program, that receives files, and then stores them locally for later access. This program is run on a Windows 2000 Server computer as a system service. Some of the files also need to be copied over to another computer, that is running Windows 2000 Professional version. This goes all right for some time, but then I start receiving the following error. IOException: No more connections can be made to this remote...
0
1246
by: Antonio | last post by:
Hi, I am building a windows service that does the following 1) a System.Timers.Timer elapseed event handler will run code at every interval, maybe every 2 to 5 minutes or so (i have not decided yet) 2) in the Elapseed event the service will query a table in sql server and find the 1 oldest row in a table and set the status of that row to 'running' 3) the service will then run a report on the sql server database and save the results to a...
3
2613
by: Chris Dunaway | last post by:
I am writing a Windows Service that reads and processes files on a set schedule. I want to create a second app that can monitor the Windows service. The Windows service will write trace messages at certain points while executing. The monitoring app I want to write will be very simple, just picking up these traces and displaying them to show progress of the service. My question is what is the best method of communication between the...
0
1486
by: JM | last post by:
I am working on an application which uses xml file as a database. The application has 2 interfaces which accesses this xml file. "Windows application written in C#" and "Windows Service written in C#". Both have been developed in .NET Framework 2.0. Recently I have started getting error in Windows application that "xml file is being locked by some other process". I have debugged and find out that its my Windows Service which is locking...
1
1956
by: Mahesh Devjibhai Dhola | last post by:
Hi, Scenario: The webservice was developed on windows 2000 Pro and deployed previously on windows XP pro for testing. We have tested for many days. The client for that service was 30+ and accessing the webservice each min. It was working 100% fine. Problem: But now in actual deployment, we have deployed webservice in Win Server 2003 and we have used all the default configurations. Now the clients are accessing that service the same way...
0
1052
by: sriksdave | last post by:
Alright, Here is my situation I have created a multithreaded app with a windows service that does some File Input output operations and running of excel macros from a network location. I need to run this multithreaded application continuously. I am thinking scheduled task is not a great idea in the sense that the starting and the stopping (graceful exit of all the threads) will not be possible. If i create a service.... I...
3
2597
by: Mika M | last post by:
I'm programming quite simple Windows Service using C# 2005. I also made setup for it into same solution. When I run setup to install service, it's going fine into C:\Program Files\MyCompany\My Service, and Event Log tells... Event Type: Information Event Source: MsiInstaller Event Category: None Event ID: 11707
0
9584
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9397
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9344
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8264
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6810
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4893
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.