Results 1 to 5 of 5

Thread: Windows Service

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    7

    Windows Service

    Hi Guys,

    I have written a Windows Service which has Timer and Event Log Controls. After every 3 seconds, the service must write the list of files in a mapped directory on the network to the Event Log.

    Here is the part of the code that I am trying to get working....

    Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
    Dim di As New DirectoryInfo("u:\pro\inv-reports")
    ' Create an array representing the files in the current directory.
    Dim fi As FileInfo() = di.GetFiles()
    ' Print out the names of the files in the current directory.
    Dim fiTemp As FileInfo
    For Each fiTemp In fi
    EventLog1.WriteEntry("Filename :" + fiTemp.Name)
    Next fiTemp
    Beep()
    End Sub


    The above code is supposed to print the files present in "u:\pro\inv-reports" directory to the event log (Here "u" is a mapped network drive). However, it does not work.


    But the code below which access the director "c:\bin" on the local machine, works!

    Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
    Dim di As New DirectoryInfo("c:\bin")
    ' Create an array representing the files in the current directory.
    Dim fi As FileInfo() = di.GetFiles()
    ' Print out the names of the files in the current directory.
    Dim fiTemp As FileInfo
    For Each fiTemp In fi
    EventLog1.WriteEntry("Filename :" + fiTemp.Name)
    Next fiTemp
    Beep()
    End Sub


    So, I tried something else. I tried to access the network drive using a windows console application rather than a windows service. And to my surprise, it worked...
    Imports System.IO

    Module Module1

    Sub Main()
    Dim di As New DirectoryInfo("u:\pro\inv-reports")
    ' Create an array representing the files in the current directory.
    Dim fi As FileInfo() = di.GetFiles()
    Console.WriteLine("The following files exist in the print directory:")
    ' Print out the names of the files in the current directory.
    Dim fiTemp As FileInfo
    For Each fiTemp In fi
    Console.WriteLine(fiTemp.Name)
    Next fiTemp
    Console.ReadLine()
    End Sub

    End Module


    Can't a windows service access a network drive? I did set it up as a network service.

    All suggestions/ideas are welcome

    Thanks in anticipation.
    Shashi

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Its probably a permissions issue. When you run a service it doesn't run under a specific user account so the account it is using probably doesn't have permissions to access the network store. Try having it run as a specific user. That would also explain why the code works under different kinds of projects (windows or console) because then you are running it as your user account.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    7
    Thanks for your immediate reply. It makes sense. But I am having another problem now.

    I changed the Account type (of ServiceProcessInstaller) from NetworkService to User. When I rebuilt the solution and tried installing it, I am asked to enter user name and password. I entered my username and password for this windows machine but I am given the following error message ...
    "The account name is invalid or does not exist, or the password is invalid for the name specified".

    That's surprising because, I am sure the username and password are correct ! (And the CAPSLOCK is not ON)

    I tried something else too..
    When the "Set Service Login" dialog-box appears while installing the service, I now typed "abcd" in the "Username" field (a non existent account) and typed "1234" in the "Password" and "Confirm Password" fields. It gives me a different error message.. "No mapping between account names and security IDs was done". Does this help in narrowing my problem?

    All pointers are welcome.

    Thank you
    Shashi

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    7
    Guess what! I finally managed to install the service using my "User" account. You know what the problem was, I had to type in the username in "ComputerName\Username" format!

    However, I still cannot access my mapped network drive! hahaha I am going crazy now. Tell me what to do?

    Thanks
    Shashi

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    7
    I got it working finally! All I had to do was use the whole path to the network drive rather than using a mapped drive.

    Thanks for your replies.

    Shashi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width