By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,238 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,238 IT Pros & Developers. It's quick & easy.

File.Copy() problem

P: n/a
I've written a windows service in C#.

The service copies certain files using a FileSystemWatcher.

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?
Jan 17 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Code Monkey wrote:
I've written a windows service in C#.

The service copies certain files using a FileSystemWatcher.

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.
Jan 17 '08 #2

P: n/a
"Code Monkey" <dl********@gmail.comwrote in message
news:a1**********************************@j20g2000 hsi.googlegroups.com...
I've written a windows service in C#.

The service copies certain files using a FileSystemWatcher.

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.
Jan 17 '08 #3

P: n/a
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
Jan 20 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.