Link to home
Start Free TrialLog in
Avatar of b_o_b
b_o_b

asked on

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.
Avatar of Lacutah
Lacutah
Flag of United States of America image

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.
Avatar of b_o_b
b_o_b

ASKER

Need some further explanation
ASKER CERTIFIED SOLUTION
Avatar of Lacutah
Lacutah
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial