Solved

Copying files with DLL's - Urgent

Posted on 2007-04-09
4
240 Views
Last Modified: 2012-05-05
Hello all,
I have a VB.net (.net 2003) windows service which includes in it a C# .dll. This dll has a variety of responsibilites, among which is to copy a file from one machine to another. The code works perfectly except for the line of code which does the copying:
System.IO.File.Copy(sourceFilePath,targetFilePath,true);
I am using the System.IO.File object to do the copying. At the top of the dll, I have the "directive": using System.IO; The error I am getting is: Cannot find file...  but the file IS there. I wrote a quick sample windows forms application to copy the file, and it works fine. The windows service is running on the target machine, and the source file is sitting on another machine. Both are on their own private network. I am specifying the source path by using UNC:  \\10.1.1.1\SourceFolder\fileName.  Both machines have the same user account, for ease of accessibility, the source folder is shared, and I have gone through the sharing and security permissioning to make sure everything is right. Could this have something to do with the fact that I am trying to copy files from within a running windows service??  Do I need to add the Network Service user to something?
This is very high priority for me - I have a deliverable tomorrow. Hardware is being shipped out!
Any help would be appreciated. Thanks.
0
Comment
Question by:imkiosks
  • 2
4 Comments
 
LVL 22

Expert Comment

by:cookre
Comment Utility
The security context of a service is a bit different from user started programs, in that you have to specify, when you create the service, the account under which the service will run.

Also note that SystemLocal only has rights on the box it's running on.

0
 
LVL 13

Accepted Solution

by:
Corey2 earned 500 total points
Comment Utility
Change your service to run under the user instead of system
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/sys_srv_logon_user.mspx?mfr=true

This will make any application that is run by the service run under the user.

Services by default run under the System account which doesn't have any access to network shares.
0
 

Author Comment

by:imkiosks
Comment Utility
OMG,
Of course, of course, of course!!!!
I knew that. I have done just that many times before. Shame on me for overlooking such a simple setting. Well, when you're under pressure - nothing works right (i guess...  :-/ )

Thanks, Corey - you saved my butt.
0
 
LVL 13

Expert Comment

by:Corey2
Comment Utility
No problem my pleasure
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A short article about a problem I had getting the GPS LocationListener working.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now