[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


.net Windows Service - access to folder on LAN is denied

Posted on 2010-08-23
Medium Priority
Last Modified: 2012-05-10

I just created a windows service (as per below) which simply copies a file every 10 seconds (I will change that to just once a day... just want to backup a file on the server onto the LAN). I changed the ip address just to 'ipaddress' but the error message below leads me to think that it can find the file ok, but I just can't access it as my access to that folder is denied. The code works fine when i copy to my local pc but just not when trying to copy from local pc to LAN.

I did read, however, that windows services run under the system account and don't have access to the network. If so, how to gain access... or how to achieve what i want to achieve?

error message: (not too sure what first part is... something missing i guess for my computer to be able to display it.

The description for Event ID ( 0 ) in Source ( Application ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: Copy Failed: Access to the path '\\\DEPT\CSO\OBO\BRA\BRA\Sita Account\Aiden\TestLAN\CTA Test.mdb' is denied..

Imports System.Timers
Imports System.IO
Imports System.Net

Public Class CSATService
   Private t As Timer = Nothing

   Protected Overrides Sub OnStart(ByVal args() As String)
      ' Add code here to start your service. This method should set things
      ' in motion so your service can do its work.


   End Sub

   Protected Overrides Sub OnStop()
      ' Add code here to perform any tear-down necessary to stop your service.
   End Sub

   Protected Sub t_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)

         Dim copyFile As FileInfo = New FileInfo("E:\Test\CTA Test 2010.06.30.mdb")
         copyFile.CopyTo("\\ipaddress\TestLAN\CTA Test.mdb", True)
      Catch ex As Exception
         System.Diagnostics.EventLog.WriteEntry("Application", "Copy Failed: " & ex.Message.ToString)
      End Try

   End Sub

   Public Sub New()

      ' This call is required by the Windows Form Designer.

      ' Add any initialization after the InitializeComponent() call.
      t = New Timer(10000)
      AddHandler t.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf t_Elapsed)

   End Sub
End Class

Open in new window

Question by:AidenA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 22

Expert Comment

ID: 33499258

If you have proper rights to access "\\\DEPT\CSO\OBO\BRA\BRA\Sita Account\Aiden\TestLAN\CTA Test.mdb", it's probably that the file is in use by SQL Server. Also, you shouldn't copy the datafile as you can't just copy it back. You can create a backup job and then copy that bak file.


Author Comment

ID: 33499289
hi, well i have access rights ok, as i can access the folder myself from the windows explorer.

I don't use sql server, the file is an MS Access file. Not sure what you mean here?

This is the first windows service i've created... so not sure what you mean in your third point either! What do you mean I shouldn't copy the datafile as I can't copy it back? (don't want to copy it back anyway?) I can create a backup job and then copy the back file? Sorry you lost me there?
LVL 22

Accepted Solution

pivar earned 2000 total points
ID: 33499345
Sorry, I thought it was a sql server datafile. In case of an Access datafile, you can ignore the points about not being able to copy and backup job. But it could still be a problem with the file being in use.

But if the service is running with the system account, that is probably the cause. This account doesn't have access on the lan. It doesn't matter whether your own user has access or not. You can change user under Logon properties for the service.


Author Comment

ID: 33499452
ah, very good... i went into properties of the service and under logon it showed


so i changed it to NT AUTHORITY\NetworkService and just set my own password and it worked.

Thanks! Hopefully it will also work on the server...

LVL 11

Expert Comment

ID: 33499488
Depending on the type of network it is normally best practice to have a (or a number of) service accounts (normally domain accounts, assuming your computers are part of a domain). You should then run the service using the credentials of a domain account which has permission to the relevant paths.


Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Online collaboration is quickly becoming embedded in the workplace, and its benefits are tangible. See what the current landscape looks like and what the future holds for collaboration tools and the future of work.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

656 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