Copy Files to computers on a Network using a Windows Service

Aim:
   Be able to copy files to different computers(on a network) using a Windows Service

Project:
  Using a Windows Service, it calls a frmService.vb (VB.NET Windows Form) that contains a function which performs actions such as downloading files from FTP to my computer and deploying files to different computers on a network (to a shared folder).

Problem:
  Downloading a file from FTP is OK, but, copying (deploying) the files to computers on a network raises an error saying: ...

================================================================
System.IO.IOException: The network path was not found
 at System.IO._Error.WinIOError(Int32 errorCode, String str)
 at System.IO.File.InternaleCopy(String sourceFileName, String destFileName, Boolean Overwrite)
 at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean OverWrite)
 at v2k_functions.filecopy(String srcFile, String destFile)
 ===============================================================

===============================================================
System.UnauthorizedAccessException: Access to the path "\\NAME\A\B\abc.mde" is denied.
  System.IO.IOException: The network path was not found
 at System.IO._Error.WinIOError(Int32 errorCode, String str)
 at System.IO.File.InternaleCopy(String sourceFileName, String destFileName, Boolean Overwrite)
 at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean OverWrite)
 at v2k_functions.filecopy(String srcFile, String destFile)
================================================================

Here is the Function that performs the copying of a file to computers:  

 Function filecopy(ByVal srcfile As String, ByVal destfile As String)
        Try
            Dim x As IO.File
            x.Copy(srcfile, destfile, True)
            Return True
        Catch e1 As Exception
            MsgBox(e1.ToString)
            Return False
        End Try
    End Function

For x = 0 to arrNames.Length - 1

    Dim dest1 As String    
    dest1 = "\A\B\abc.mde"
         
    If filecopy("C:\V2KSUS\Visual 2000 Report.mde", "\\" + arrNames(x) + dest1) = False Then
       ' If successful then put them in an array
   Else
       ' Count how many computers that has been copied successfully
    End If

Next


Possible Cause:
   - Since I installed the Windows Service using a LOCAL SYTEM account, I might have no access to computers in the network.

************************************************************************
>> If I install the service using a NETWORK SERVICE or LOCAL SERVICE account, it does not work.

      Possible Cause:
   - The frmService.vb has MessageBox and ProgressBar, it does not allow any MessageBox or any interface. Using the LOCAL SYSTEM allows to interact with the desktop.

  >> On the other hand, I also tried executing the form without using a Windows Service and it works perfectly.
b_o_bAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LacutahCommented:
This is not a .NET problem, make sure the service is running under a domain account that has access to all of the computers that need to be connected to.  For example, since it works perfectly when you're running it, use your own credentials.
0
b_o_bAuthor Commented:
Need some further explanation
0
LacutahCommented:
If you go to Compuer Management, and the Services section, You can see the properties for the services installed and or running on the computer.  If you go to the property pages for the services, you can configure who the service runs as.  If the service you wrote is running under the local system account, it will not have access to any other computers on the network.  If, however, you change the account the service is running under to be yours - ie, someone who DOES have permissions to access other computers - the service will be able to copy / move the files.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.