473,385 Members | 1,324 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.

Windows Service accessing Excel file :(

emibt08
25
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\DataProcApplication\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 34036
balabaster
797 Expert 512MB
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
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 Expert 512MB
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
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 ServiceInstaller 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:\TestExcelFiles\TestBook1.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.

Then i called that console app with CreateProcessAsUser 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
Any resolution on this? I am having the same problem.
Jan 8 '09 #6
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 Expert 512MB
Try the following
1. Install your service using latest version of installutil..."\WINDOWS\Microsoft.NET\Framework\ve rsion"
2. Try installing the following ....Download details: 2007 Microsoft Office System Update: Redistributable Primary Interop Assemblies
3. Check on "MasterEvilAce" 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 "initialized" 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
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 "interactive 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. * "Interactive 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
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
emibt08, I've been attempting to get this working for awhile now wondering what you mean by:

@emibt08
Where it is my understanding that the 'isolated storage' is a persistent storage medium for storing user configuration information... do you just mean that you spawn the application from within the service? or am I missing something?

Thanks, I'm getting a lot of heat to get this working

Matt
May 19 '09 #11
I found another solution on this site:
http://social.msdn.microsoft.com/For...?prof=required

For 64-bit (x64), create this folder:
C:\Windows\SysWOW64\config\systemprofile\Desktop

For 32-bit (x86), create this folder:
C:\Windows\System32\config\systemprofile\Desktop

Personally, I had the problem on a VISTA x86 system. I created the folder as described in the 32-bit option above, and it solved my problem.

The windows service, if running under the systemprofile, needs the Desktop folder. This folder was automatically created on XP and older Windows Server versions, but not for Vista and Windows 2008 Server.
Mar 2 '10 #12
csharper66 - that worked like a charm. i'm on win 7 x64 and have been struggling with this. thank you!!!!
Sep 21 '10 #13
If you just need to read the file why do the automation? You could just just oledb jet engine provider to read the file. If you need to create then use an xslt.
Sep 22 '10 #14
csharper66 - Thanks. I agree with H Ogawa that it is safer than "registry hack".
Nov 10 '10 #15
You can only upload open files from C:\Windows\System32\config\systemprofile\Desktop
If the directory does not exist create it.
Saves changing the registry.
You can add sub dirs..
Nov 11 '10 #16
That's great

It's work for me, thanks.

I was lost my hair
Oct 26 '18 #17

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

Similar topics

0
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...
2
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...
4
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...
0
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...
3
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...
0
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...
1
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...
0
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...
3
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
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?
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...

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.