WNetAddConnection2 from a Windows Service

Posted by Flavio on Stack Overflow See other posts from Stack Overflow or by Flavio
Published on 2010-06-03T17:41:38Z Indexed on 2010/06/03 17:44 UTC
Read the original article Hit count: 295

Filed under:
|
|

I'm trying to connect to a remote password protected shared folder from a Windows service, which runs as LocalSystem account. It seems that the LocalSystem account is unable to directly access password-protected network shares using WNetAddConnection2() or similar calls. Can anyone confirm this? I've read that impersonating an administrator user might be the way to go. I've tried using LogonUser() and ImpersonateLoggedOnUser() before WNetAddConnection2(), it appears that the mount of the network path succeeds, but then actual accesses (e.g. enumerating of files in remote folder) fail. Any ideas?

Thanks.

© Stack Overflow or respective owner

Related posts about Windows

Related posts about service