File.Copy() problem

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

    #1

    File.Copy() problem

    I've written a windows service in C#.

    The service copies certain files using a FileSystemWatch er.

    However, where it copies the files to is a windows share (\\ipaddress
    \sharename).

    If I set the service up and run it as a user who has access to this
    share -

    Services Service Name Log On As etc,etc

    it copies the files.

    If I leave the default settings, the copy does not take place.

    How do I impersonate a user who has access to the network share from
    with in the service?
  • Jeroen Mostert

    #2
    Re: File.Copy() problem

    Code Monkey wrote:
    I've written a windows service in C#.
    >
    The service copies certain files using a FileSystemWatch er.
    >
    However, where it copies the files to is a windows share (\\ipaddress
    \sharename).
    >
    If I set the service up and run it as a user who has access to this
    share -
    >
    Services Service Name Log On As etc,etc
    >
    it copies the files.
    >
    If I leave the default settings, the copy does not take place.
    >
    How do I impersonate a user who has access to the network share from
    with in the service?
    Why do you want to? You can just run the service under its own account,
    which has exactly the permissions it needs. This is the most secure setup.

    Alternatively, run the service under "Network service" credentials and give
    the local machine account the service runs on (<MACHINENAME>$ ) permissions
    on the share.

    Impersonation is quite annoying in .NET, and you don't want to bother with
    it unless there's a solid reason. You don't need to go that route just to be
    able to access a share.

    --
    J.

    Comment

    • Willy Denoyette [MVP]

      #3
      Re: File.Copy() problem

      "Code Monkey" <dlynes2005@gma il.comwrote in message
      news:a1b60fa8-9bac-4987-8e47-128c76502df7@j2 0g2000hsi.googl egroups.com...
      I've written a windows service in C#.
      >
      The service copies certain files using a FileSystemWatch er.
      >
      However, where it copies the files to is a windows share (\\ipaddress
      \sharename).
      >
      If I set the service up and run it as a user who has access to this
      share -
      >
      Services Service Name Log On As etc,etc
      >
      it copies the files.
      >
      If I leave the default settings, the copy does not take place.
      >
      How do I impersonate a user who has access to the network share from
      with in the service?


      Do as Jeroen suggest, run your service in the account that has access to the
      share. Stay away from Impersonation whenever you can.

      Willy.


      Comment

      • christery@gmail.com

        #4
        Re: File.Copy() problem

        I used another way, not a M$ computer connecting, using FTPand then it
        all works.. tried samba, nfs and a lot of other but ftp seems to work
        best.. rather that than writing something of my own,,,
        //CY

        Comment

        Working...