Solved

Copying files with DLL's - Urgent

Posted on 2007-04-09
4
242 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
ID: 18879098
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
ID: 18879522
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
ID: 18881540
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
ID: 18881860
No problem my pleasure
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A short article about problems I had with the new location API and permissions in Marshmallow
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

816 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

8 Experts available now in Live!

Get 1:1 Help Now