acadia
acadia

Reputation: 2333

Windows Service not able to access mapped folders

I have a very simple VB.net Windows Service written using VS.net 2008. The program after doing several other functions writes a log in one of the network folders. The code is as shown below: If I change the path from "Y:\Activity_Log" to "C:\Activity_Log" it is working like a charm.

What is the problem if I use Y drive which is a valid one and I am able to access it from other VB.net desktop apps. Please help.

Dim strFile As String = "Y:\Activity_Log\" & DateTime.Today.ToString("dd-MMM-yyyy") & ".txt"
        Dim fs As FileStream = Nothing
        Dim activityfolder As String = "Y:\Activity_Log"
        Dim di As System.IO.DirectoryInfo

        di = New System.IO.DirectoryInfo(activityfolder)

        If (Not di.Exists) Then
            di.Create()
        End If


        If (Not File.Exists(strFile)) Then
            Try
                Dim sw1 As New StreamWriter(File.Open(strFile, FileMode.OpenOrCreate))
                sw1.WriteLine("******************************Activity Log for " & Now.Date & "*******************")
                sw1.WriteLine("-----------------------------------------------------------------------------------------------------------------")
                sw1.WriteLine(Remarks & " ---" & DateTime.Now)
                sw1.Close()
            Catch ex As Exception

            End Try

        Else
            Dim sw As StreamWriter
            sw = AppendText(strFile)
            sw.WriteLine(Remarks & " ---" & DateTime.Now)
            sw.Close()

        End If

Upvotes: 0

Views: 830

Answers (2)

Sean
Sean

Reputation: 936

Start->Control Panel->Administrative Tools->Services

Find Your service in the list, right click on the name, Properties

Click the Log On tab

Change from Local System account to 'This Account'

Use a user that has access to that share, start with your username/password to convince yourself that it works ;)

Click Ok, then restart the service.

Upvotes: 4

Fredou
Fredou

Reputation: 20140

maybe you need to run the service under a user that has access to that drive?

maybe the generic service user doesn't have access.

Upvotes: 3

Related Questions