[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Copy Files to computers on a Network using a Windows Service

Posted on 2004-11-23
3
Medium Priority
?
997 Views
Last Modified: 2011-10-03
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.
0
Comment
Question by:b_o_b
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Lacutah
ID: 12659824
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
 

Author Comment

by:b_o_b
ID: 12659959
Need some further explanation
0
 
LVL 9

Accepted Solution

by:
Lacutah earned 600 total points
ID: 12660739
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Screencast - Getting to Know the Pipeline
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

831 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