I'm working on a Windows Service that one of its tasks is archiving files on remote machine but I've a problem regarding access privileges in case of Workgroup.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The simplest way is to mirror the username and password on both machines, creating the same account on both machines, then run your service under that account. As you're in a workgroup and not a domain the remote login will work, but once you're in a domain that no longer works.
You cannot use any of the built in service accounts (Network Service, Local Service, Local System for this)
回答2:
You can run it under user account that has access privileges on remote machine.
Or you can use impersonation when accessing remote machine. For impersonation you will need username and password that has access to remote machine. Look here for some code on impersonating in .net http://blogs.msdn.com/shawnfa/archive/2005/03/22/400749.aspx