Access files from .NET Windows Service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom

    #1

    Access files from .NET Windows Service

    Is it possible to access (Read via StreamReader) an external file from
    a Wndows service? I.E. In the OnStart method of the service, I need to
    go out and read a couple of external files (and these files appear on a
    differnet server and are accessed via a UNC syntax - i.e.
    \\server\share\ myfile.txt). I tried this under my VB.NET service but it
    keeps telling me that I have an unauthorized file access when my
    service starts up)

    Thanks.

    --

  • Izzy

    #2
    Re: Access files from .NET Windows Service

    Sounds like a permissions issue. I'd create a user accout for the
    service to use and give this user read\write permissions to the share.

    Israel

    Tom wrote:
    Is it possible to access (Read via StreamReader) an external file from
    a Wndows service? I.E. In the OnStart method of the service, I need to
    go out and read a couple of external files (and these files appear on a
    differnet server and are accessed via a UNC syntax - i.e.
    \\server\share\ myfile.txt). I tried this under my VB.NET service but it
    keeps telling me that I have an unauthorized file access when my
    service starts up)
    >
    Thanks.
    >
    --

    Comment

    • Tom

      #3
      Re: Access files from .NET Windows Service

      Hmm... that is kinda ugly... Is there a way that I can simply add the
      system account (the one the service is currently running under) to the
      share's read/write permissions?
      --



      Izzy wrote:
      >Sounds like a permissions issue. I'd create a user accout for the
      >service to use and give this user read\write permissions to the share.
      >
      >Israel
      >
      >Tom wrote:
      >Is it possible to access (Read via StreamReader) an external file
      >>from a Wndows service? I.E. In the OnStart method of the service,
      >>I need to go out and read a couple of external files (and these
      >>files appear on a differnet server and are accessed via a UNC
      >>syntax - i.e. \\server\share\ myfile.txt). I tried this under my
      >>VB.NET service but it keeps telling me that I have an unauthorized
      >>file access when my service starts up)
      >>
      >Thanks.
      >>
      >--

      Comment

      • Izzy

        #4
        Re: Access files from .NET Windows Service

        I've got 2 or 3 windows services and some other apps that need to
        access network drives and databases. I find it easy to have them all
        run under the same user account "Robot".

        But if you don't want to go that route then just change the folders
        permissions to allow anyone to read and write.

        But if security is an issue, I'd set up a user account.


        Tom wrote:
        Hmm... that is kinda ugly... Is there a way that I can simply add the
        system account (the one the service is currently running under) to the
        share's read/write permissions?
        --
        >
        >
        >
        Izzy wrote:
        >
        Sounds like a permissions issue. I'd create a user accout for the
        service to use and give this user read\write permissions to the share.

        Israel

        Tom wrote:
        Is it possible to access (Read via StreamReader) an external file
        >from a Wndows service? I.E. In the OnStart method of the service,
        >I need to go out and read a couple of external files (and these
        >files appear on a differnet server and are accessed via a UNC
        >syntax - i.e. \\server\share\ myfile.txt). I tried this under my
        >VB.NET service but it keeps telling me that I have an unauthorized
        >file access when my service starts up)
        >
        Thanks.
        >
        --

        Comment

        Working...